I am trying to write a bash
script to get all IP addresses on a server. The script should work on all major distros. Here is what I have:
ifconf
ifconfig
was obsoleted by ip
. It also has the flag -o
that write outputs easy to parse. Use ip -4
to show only IPV4 addresses. Note the simpler script, it already exclude the loopback address:
ip -o addr | awk '!/^[0-9]*: ?lo|link\/ether/ {print $2" "$4}'
Or if you don't want the networks:
ip -o addr | awk '!/^[0-9]*: ?lo|link\/ether/ {gsub("/", " "); print $2" "$4}'