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

link|improve this question

56% accept rate
feedback

2 Answers

up vote 5 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.

link|improve this answer
2  
worked also ifconfig eth1| awk -F ' *|:' '/inet addr/{print $4}' – user47556 Oct 27 '10 at 11:37
1  
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
feedback

maybe this will help

ifconfig eth1
link|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
feedback

Your Answer

 
or
required, but never shown

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