CentOS Linux or Ubuntu Linux – Get List of ip addresses on Server

By | 2013/04/30

Here’s a quick one-liner to spit out all ip addresses from ifconfig:


$ /sbin/ifconfig | grep 'inet addr' | awk '{print $2}' | cut -c6-

Ex:

$ /sbin/ifconfig | grep 'inet addr' | awk '{print $2}' | cut -c6-
172.16.218.10
172.16.218.12
172.16.218.14
172.16.218.66
172.16.218.67
172.16.218.68
172.16.218.69
172.16.218.70
172.16.218.74
172.16.218.75
172.16.218.76
172.16.218.77
172.16.218.78
172.16.218.90
172.16.218.91
172.16.218.92
172.16.218.93
172.16.218.94
172.16.218.98
172.16.218.99
172.16.218.100
172.16.218.101
172.16.218.102
127.0.0.1

This works on CentOS and Ubuntu, and perhaps others though you may have to adjust the column number ($2).