This post will quickly guide about how to Linux get ip address, subnet and related networking information.
Ifconfig – command for Linux get ip address:
In Linux in order to check or get Linux ip address you need to use command “/sbin/ifconfig”.Along with the ip address it also It displays Mac address, subnet mask and other information.
Sample Output
[root@rhel1 ~]# /sbin/ifconfig eth0 Link encap:Ethernet HWaddr 00:50:5B:AB:70:BA inet addr:192.168.49.180 Bcast:192.168.51.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:815056731 errors:0 dropped:0 overruns:0 frame:0 TX packets:87925348 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:24778546688 (23.0 GiB) TX bytes:24660778043 (22.9 GiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:61868986 errors:0 dropped:0 overruns:0 frame:0 TX packets:61868986 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:8952532443 (8.3 GiB) TX bytes:8952532443 (8.3 GiB) [root@rhel1 ~]#
To get only the ip address in the above out put which will also remove loop back lo entry from the output use below command:
[root@rhel1 ~]# /sbin/ifconfig|grep -v "127.0.0.1"|grep -i "inet addr" inet addr:192.168.49.180 Bcast:192.168.51.255 Mask:255.255.255.0 [root@rhel1 ~]#
As per the output above “192.168.49.180” is the ip address of the Linux system which is being assigned to the interface eth0.
In case you have multiple interface card or Ethernet card such eth0, eth1 … ethn. Then to get ip address of specific Ethernet you need to specify in the ifconfig command as below.
[root@rhel1 ~]# /sbin/ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:50:5B:AB:70:BA inet addr:192.168.49.180 Bcast:192.168.51.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:815073128 errors:0 dropped:0 overruns:0 frame:0 TX packets:87926953 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:24779723094 (23.0 GiB) TX bytes:24661225962 (22.9 GiB) [root@rhel1 ~]#
ip addr show – command for Linux get ip address:
As per the recommendation we must use ip addr show in Linux get ip address.
[root@aysbbss01 ~]# ip addr show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:50:5b:ab:70:ba brd ff:ff:ff:ff:ff:ff inet 192.168.49.180/22 brd 192.168.51.255 scope global eth0
ip r l -command for Linux get ip address:
There is one more easy to use command in Linux to get or find ip address , as below:
[root@rhel1 ~]# ip r l 192.168.48.0/22 dev eth0 proto kernel scope link src 192.168.49.180 default via 192.168.51.1 dev eth0 [root@rhel1 ~]#
Leave a Reply