Quick Start Guide: How to Find IP Address in Linux

This post is about how to get IP address, subnet and related network information in Linux.

Ifconfig – Linux command:

On Linux, to check or find out the IP address, you must use the “/ sbin / ifconfig“ command. The MAC address, subnet mask and other information are also displayed.

Output example

[[email protected] ~]# /sbin/ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                                                                                    
        inet 213.159.209.228  netmask 255.255.254.0  broadcast 213.159.209.255                                                                                
        inet6 fe80::5054:ff:fe80:19a4  prefixlen 64  scopeid 0x20<link>                                                                                       
        ether 52:54:00:80:19:a4  txqueuelen 1000  (Ethernet)                                                                                                  
        RX packets 306877603  bytes 20085789908 (18.7 GiB)                                                                                                    
        RX errors 0  dropped 0  overruns 0  frame 0                                                                                                           
        TX packets 14979556  bytes 128723797704 (119.8 GiB)                                                                                                   
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0                                                                                            
                                                                                                                                                              
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536                                                                                                                  
        inet 127.0.0.1  netmask 255.0.0.0                                                                                                                     
        inet6 ::1  prefixlen 128  scopeid 0x10<host>                                                                                                          
        loop  txqueuelen 1  (Local Loopback)                                                                                                                  
        RX packets 10034610  bytes 35020478823 (32.6 GiB)                                                                                                     
        RX errors 0  dropped 0  overruns 0  frame 0                                                                                                           
        TX packets 10034610  bytes 35020478823 (32.6 GiB)                                                                                                     
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0 
[[email protected] ~]#

To get only the IP address:

[[email protected] ~]# /sbin/ifconfig|grep -v "127.0.0.1"|grep -i "inet addr"
          inet addr:213.159.209.228  Bcast:213.159.209.255  Mask:255.255.255.0
[[email protected] ~]#

According to the conclusion above “192.168.49.180”Is the IP address of the Linux system that is currently assigned to the interface eth0

In case you have more than one interface card or Ethernet card, for example eth0, eth1… ETHN. Then, to get the IP address of a specific Ethernet you need to specify in the IFCONFIG command as shown below.

[[email protected] ~]# /sbin/ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500                                                                                                    
        inet 213.159.209.228  netmask 255.255.254.0  broadcast 213.159.209.255                                                                                
        inet6 fe80::5054:ff:fe80:19a4  prefixlen 64  scopeid 0x20<link>                                                                                       
        ether 52:54:00:80:19:a4  txqueuelen 1000  (Ethernet)                                                                                                  
        RX packets 306923321  bytes 20088708252 (18.7 GiB)                                                                                                    
        RX errors 0  dropped 0  overruns 0  frame 0                                                                                                           
        TX packets 14980805  bytes 128725514772 (119.8 GiB)                                                                                                   
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[[email protected] ~]#

ip addr show – command in Linux to get the IP address:

As recommended, we should use ip addr show on Linux to get the IP address.

[[email protected] ~]# 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 rl – Linux command to get IP address:

There is one easier-to-use command in Linux to get or find an IP address, as shown below:

[[email protected] ~]# ip r l
213.159.209.0/22 dev eth0  proto kernel  scope link  src 213.159.209.228
default via 213.159.209.1 dev eth0
[[email protected] ~]#

Sidebar