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?

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 '18 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.