List All Network Interfaces on Red Hat

The following script will list all non-loopback networking interfaces on a Fedora, Red Hat or downstream distribution.


interfaces=$(ls /etc/sysconfig/network-scripts/ifcfg-* | 
            LC_ALL=C sed -e "$__sed_discard_ignored_files" 
                       -e '/(ifcfg-lo$|:|ifcfg-.*-range)/d' 
                       -e '{ s/^ifcfg-//g;s/[0-9]/ &/}' | 
            LC_ALL=C sort -k 1,1 -k 2n | 
            LC_ALL=C sed 's/ //')

echo $interfaces | tr " " "n"

It ignores any aliases and outputs the interfaces one per line.

Comments are closed.