SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Thursday, December 18, 2008

Find out the IP address assigned to eth0 and display IP only

If i want to know about the Ip address of the linux machine,simply i will be typeing the command ifconfig.It will display all the details about the eth0 as

eth0 Link encap:Ethernet HWaddr 00:1c:c0:18:b1:1d
inet addr:192.168.1.230 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::21c:c0ff:fe18:b11d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:145966 errors:0 dropped:0 overruns:0 frame:0
TX packets:101875 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:142716773 (136.1 MB) TX bytes:14740051 (14.0 MB)
Memory:e3200000-e3220000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8799 errors:0 dropped:0 overruns:0 frame:0
TX packets:8799 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6702165 (6.3 MB) TX bytes:6702165 (6.3 MB)


If i want to get the ipaddress of eth0,follow the steps as given below

$ ifconfig eth0


eth0 Link encap:Ethernet HWaddr 00:1c:c0:18:b1:1d
inet addr:192.168.1.230 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::21c:c0ff:fe18:b11d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:146276 errors:0 dropped:0 overruns:0 frame:0
TX packets:102052 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:142798351 (136.1 MB) TX bytes:14776261 (14.0 MB)
Memory:e3200000-e3220000

Now you just wanted the IP address, use grep to get the IP

$ ifconfig eth0| grep 'inet addr:'

inet addr:192.168.1.230 Bcast:192.168.1.255 Mask:255.255.255.0

To get IP address from use cut command

$ ifconfig eth0 | grep 'inet addr:' | cut -d: -f2


192.168.1.230 Bcast

Remove Bcast with awk

$ ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'

192.168.1.230