Useful bash oneliner: List Server IP Addresses

for i in $(/sbin/ifconfig | grep addr: | cut -d’:’ -f2 | cut -d’ ‘ -f1 | grep -Ev ‘^$’); do echo -n $i”, “; done | sed -r s/’, $’/”/g; echo

5 thoughts on “Useful bash oneliner: List Server IP Addresses

  1. Looks like "done" turned into "one". I needed the same one-liner a while back, based it on ip:

    /sbin/ip addr list | sed -n 's/inet (.*)/.*/1,/p' | xargs | sed 's/,$//'

    Amazing it takes stuff like this to get a list of IPs.

  2. This is what I love about the *nix way of life. there's always so many ways of doing things. What differentiates the men from the boys (as it were) is not how something gets done but that something gets done. 😀

  3. Here's one more (worked on CentOS/Fedora/RedHat-like distros):

    /sbin/ifconfig [OPTIONAL_DEVICE_NAME] | grep "Bcast" | awk -F ' ' '{print $2}' | awk -F ':' '{print $2}'

    -g

Leave a Reply