How to Check IP Address on Linux using Command Line

Channel: Linux
Abstract: inet 127.0.0.1/8 scope host loinet 192.168.10.199/24 brd 192.168.1.255 scope global eth0

How to check IP address on Linux machine using the command line interface? Mostly all of the Linux and Unix operating systems provides ifconfig and ip binary files. You can simply use these commands to find the local system IP address.

What is an IP Address?

A Internet Protocol address (IP address) is the numerical label assigned to each hardware devices connected to a computer network that uses the Internet Protocol to identify the devices. In general terms, it is an identity of any device. An IP address allows a device to communicate with other devices over an IP-based network like the LAN or Internet.

  • Read: 5 Commands to Get Public IP using Linux Terminal
Method 1 – Using ifconfig Command

ifconfig command is generally available under /sbin directory. So you will need root or sudo access to run this on many of operating systems.

ifconfig

Sample output: [Some output hidden]

eth0      Link encap:Ethernet  HWaddr 00:0C:22:83:79:A3
          inet addr:192.168.10.199  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe89:79b3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3931508 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1333146 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:706273621 (673.5 MiB)  TX bytes:857722605 (817.9 MiB)
          Base address:0x2000 Memory:fd5c0000-fd5e0000

As per above output, this system has IP address 192.168.10.199 on Ethernet interface eth0.

You can also view the specific interface details by specifying the interface name on the command line as below.

ifconfig eth0
  • Read: bash ifconfig: command not found on CentOS/RHEL 7
Method 2 – Using ip Command

ip command generally available under /bin directory but some Linux os keep is under /sbin directory. Use the following command to get ip address using ip command.

ip addr show

Sample output: [Some output hidden]

1: lo:  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
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0:  mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0C:22:83:79:A3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.199/24 brd 192.168.1.255 scope global eth0 
    inet6 fe80::20c:29ff:fe89:79b3/64 scope link
       valid_lft forever preferred_lft forever

As per the above output, this system has IP address 192.168.10.199 on Ethernet interface eth0. The interface eth1 doesn’t configure with an IP address.

You can also view the specific itnerface details using below command

ip addr show eth0

Find more commands to check local ip address of any Linux system.

ip route get 1 | awk '{print $NF;exit}'
ip route get 8.8.4.4 | head -1 | cut -d' ' -f8
ip route get 8.8.4.4 | head -1 | awk '{print $7}'

Ref From: tecadmin

Related articles