Published on

3 Different Ways to check ip address in Linux

Authors
Table of Contents

What is IP address?

IP address stands for Internet Protocol address. It is a unique address assigned to every device connected to the internet. It is a 32-bit number that is divided into 4 parts. Each part is separated by a dot.

How to check IP address in Linux?

There are many ways to check IP address in Linux. In this article we will learn about 3 different ways to check IP address in Linux.

Using ip command

ip command is used to configure and display network interfaces. It is a very powerful command and can be used to configure network interfaces, routing tables, tunnels, and much more. To check IP address in Linux you can use the following command

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
        valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
        valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 01:02:23:2a:3b:4c brd ff:ff:ff:ff:ff:ff
    inet 192.168.247.144/20 brd 192.168.255.255 scope global eth0
        valid_lft forever preferred_lft forever
    inet6 fe80::2a3b:4c/64 scope link
        valid_lft forever preferred_lft forever

Here you can see the IP address of all the network interfaces. You can also use the following command to check IP address of a specific interface

ip addr show enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 01:02:23:2a:3b:4c brd ff:ff:ff:ff:ff:ff
    inet 192.168.247.144/20 brd 192.168.255.255 scope global eth0
        valid_lft forever preferred_lft forever
    inet6 fe80::2a3b:4c/64 scope link
        valid_lft forever preferred_lft forever

In this command we are using the show option to show the IP address of a specific interface. You can find the ip address in the inet section in our example it is 192.168.247.144.

Using ifconfig command

NOTE: ifconfig command is deprecated and will be removed in future versions of Linux. You should use ip command instead.

ifconfig command is the og command to check IP address in Linux. It is used to configure and display network interfaces. You can use the following command to check IP address in Linux

ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.247.144/20 brd
        inet6 fe80::2a3b:4c/64 scope link
           valid_lft forever preferred_lft forever
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.247.144/20 brd
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever

In this output you can see the IP address of all the network interfaces in the inet section.

Using hostname -I command

hostname command is used to set or display the system's host name or domain name. You can use the -I option to display the IP address of the system. You can use the following command to check IP address in Linux

hostname -I
192.168.247.144

In this output you can see the IP address of the system.

Conclusion

In this article we learned about 3 different ways to check IP address in Linux. You can use any of these commands to check IP address in Linux.