ifconfig -a
lists all network interfaces. I need to run sudo ifconfig <iface name> down
for each interface listed by the command. What is the ideal way to implement this inside a shell script?
1 Answer
You can find the name of each network interface listed by ifconfig -a
in the directory /sys/class/net, which is populated by the kernel itself. Since the name of each directory in /sys/class/net
is the actual name of the interface, you can loop over the files.
For Example:
for intf in /sys/class/net/*; do
sudo ifconfig `basename $intf` down
done
-
Is there an alternative way to do this on Ubuntu 17.10, one that doesn't require installing net-tools first?– maqpFeb 28, 2018 at 8:08