1

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 1

3

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
1
  • Is there an alternative way to do this on Ubuntu 17.10, one that doesn't require installing net-tools first?
    – maqp
    Feb 28, 2018 at 8:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .