Using grep, sed, and awk to return a list of Activated IP Addresses

Category: Software and Systems Engineering
Author: Sean O'Donnell
Thu, May. 29th, 2008 @ 18:22:28 (MDT)

Here is a quick and dirty way to return a list of IPv4 IP Addresses that are currently configured on a computer running a Linux-based Operating System.

ifconfig | grep 'inet addr' | awk {'print $2'} | sed s/.*://

The results should appear as so:

You can also use the same approach (with grep/sed/awk) to return the IPv4 address of individual NICs as well. Simply modify the 'ifconfig' command to specify the NIC.


ifconfig eth0 | grep 'inet addr' | awk {'print $2'} | sed s/.*://

The command above will return the IPv4 Address of NIC#1 (eth0/

Copyleft (<) 1998-2019