Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

If I want to display the IP address that is assigned to eth1, how can I do this in Bash?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

Try this (Linux)

/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d: -f2| cut -d' ' -f1

or this (Linux)

/sbin/ifconfig eth0 | awk -F ' *|:' '/inet addr/{print $4}'

or this (*BSD)

ifconfig bge0 | grep 'inet' | cut -d' ' -f2

or this (Solaris 10)

ifconfig e1000g0 | awk '/inet / {print $6}'

Obviously change the interface name to match the one you want to get the information from.

share|improve this answer
worked also ifconfig eth1| awk -F ' *|:' '/inet addr/{print $4}' –  user47556 Oct 27 '10 at 11:37
On *BSD systems the ifconfig output is a bit different - ifconfig bge0 | grep 'inet' | cut -d' ' -f2 will work (substitute your appropriate interface name in place of bge0, obviously) –  voretaq7 Aug 15 '11 at 18:08
ip addr show eth1| grep inet|awk '{print $2;}' –  navaho Aug 16 '11 at 22:18

A better way: get ip adress from command "ip", because "ifconfig" is out of date. Otherwise you will get a problem on using "ifconfig", because the output of ifconfig is language dependend.

I use this command to get all IPs (IPv4):

ip addr show | grep -o "inet [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" | grep -o "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*"
share|improve this answer
ifconfig has the advantage of existing on systems that aren't Linux... –  voretaq7 Dec 7 '12 at 3:59

maybe this will help

ifconfig eth1
share|improve this answer
i know this , and its show all info i need just to get ip –  user47556 Oct 27 '10 at 11:00
like inet addr:74.86.xx.xx only the nemric ip here show in echo result , –  user47556 Oct 27 '10 at 11:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.