Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 10 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

On a Linux system

hostname -i

will give you only the IP address.

On a Solaris system use:

ifconfig e1000g0 | awk '/inet / {print $2}'
share|improve this answer

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.