≡ Menu

Linux ifdata Command: See Network Interface Info Without Parsing ifconfig Output

Reading an IP address in a shell script requires many time and various Linux distributions stores IP address in different text files. So most of us end up writing shell pipes/scripts to get the information using ifconfig | grep 'inet addr:'| grep -v '' | cut -d: -f2 | awk '{ print $1}' syntax. There is an alternative to ifconfig+shell pipe hack – ifdata command. It is a little know tool that can be used to check for the existence of a network interface and find out info about your interface such as IP, netmask, MTU and much more. No need to write shell pipes and fetch information via ifconfig or ip command. This command is designed to be easily used by a shell script.

Linux / Unix ifdata Command - Find Info About Network Interface

Fig.01: Linux / Unix ifdata Command – Find Info About Network Interface

How do I install ifdata command?

Simply type the following command at shell prompt:
$ sudo apt-get install moreutils
$ sudo yum install moreutils


Find out if the interface ppp0 exists or not, enter:

ifdata -e ppp0 && echo "Found" || echo "Not found"


ifdata -e ppp0 && echo "Found" || { echo "Not found, starting pppd..."; pppd call barISP; }

Show eth0 configuration:
$ ifdata -p eth0
Sample outputs: 1500

Get the IPv4 address of the interface, enter:

# my firewall script
# Get ip for eth0
_ip=$(ifdata -pa eth0)
## do something on $_ip ##
echo "Setting firewall for eth0 and ${_ip}..."

The complete summary of all options supported by ifdata command:

Usage: ifdata [options] iface
     -e   Reports interface existence via return code
     -p   Print out the whole config of iface
    -pe   Print out yes or no according to existence
    -pa   Print out the address
    -pn   Print netmask
    -pN   Print network address
    -pb   Print broadcast
    -pm   Print mtu
    -ph   Print out the hardware address
    -pf   Print flags
    -si   Print all statistics on input
   -sip   Print # of in packets
   -sib   Print # of in bytes
   -sie   Print # of in errors
   -sid   Print # of in drops
   -sif   Print # of in fifo overruns
   -sic   Print # of in compress
   -sim   Print # of in multicast
    -so   Print all statistics on output
   -sop   Print # of out packets
   -sob   Print # of out bytes
   -soe   Print # of out errors
   -sod   Print # of out drops
   -sof   Print # of out fifo overruns
   -sox   Print # of out collisions
   -soc   Print # of out carrier loss
   -som   Print # of out multicast
  -bips   Print # of incoming bytes per second
  -bops   Print # of outgoing bytes per second

I hope you will use this tiny too for the good.

Related Internet links
Share this on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 12 comments… add one }
  • MoChaMan69 January 29, 2013, 4:38 pm

    Here is an alternative function using /sbin/ip that gives you useful information . I call it ‘ship’ for SHow IP :

    ship ()
    [ $1 ] && DEVLIST=$1 || DEVLIST=$(ip addr show | grep ^[0-9] | cut -d: -f 2);
    for DEV in $DEVLIST;
    IP_ADDR=$(/sbin/ip addr show dev ${DEV} | grep ${DEV}$ | awk ‘{ print $2 }’ | cut -d/ -f 1);
    [ -z $IP_ADDR ] || echo “${DEV}: ${IP_ADDR}”;

    [server:~] # ship
    [server:~] #

  • Jalal Hajigholamali November 27, 2012, 6:57 am


    Thanks a lot

    we can download ifdata and other useful utilities from


  • Brian Hines November 8, 2012, 9:35 pm

    Wow, this is very helpful! Yes ifconfig can be a mess sometimes- I am always appreciative of smarter people who help dumb people like me do things quicker and better! Thanks,

  • Frank Shafer November 7, 2012, 4:46 am

    Nice tutorial buddy! ifconfig can be a bit clumsy sometimes and it’s nice to know there’s an alternative :)

  • Mac November 6, 2012, 1:27 pm

    Is ifdata available for RHEL 6 or do you need to enable another repo?

  • George November 6, 2012, 7:06 am

    So where does one find this command?

    • nixCraft November 6, 2012, 12:23 pm

      Check the related links posted at the bottom of this post.

  • Chris F.A. Johnson November 6, 2012, 5:39 am

    ifdata is not available in all distributions

  • Trey Blancher November 6, 2012, 2:43 am

    I had to install moreutils on Debian sid, because ifdata does not appear to exist as a separate package in apt.

    • nixCraft November 6, 2012, 8:01 am

      It was a typo on my part.

  • Jon November 6, 2012, 2:41 am

    Alternatively, you can use the ‘ip’ command. Its output isn’t quite as clean as ifdata, but it will always be on any modern system:

    root@host:~# ip -o -4 addr show eth0
    2: eth0 inet brd scope global eth0

    Depending on the scripting you are doing, parsing the above with awk or cut is probably preferable to an additional dependency.


Leave a Comment