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).

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

  1. Jamie

    Cool trick, though many version of “ifconfig” won’t show you subinterfaces or VIPs like eth0:0. The better way is to use the “ip” tools like “ip addr”.

    Reply
    1. Scott Miller Post author

      Thanks! I need to stop using ifconfig and move to ip… 🙂

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.