Linux Commands

How to find IP address in Linux

IP stands for the “Internet Protocol”, and it is a unique address by which a device is recognized on the internet. The IP address is different for every machine, when we go to Google, Facebook, or some other platform, it notes down the IP address by which we access that website. This address helps the internet to share information among different devices.

The IP address of any machine can be found on Linux by different commands, these commands are discussed in this article.

How to find IP address using the command in Linux

There are different commands in Linux to find IP addresses, majorly there are two types of IP addresses; public and private IP addresses; the private ip address is that which is unique and assigned to every machine and the public IP address is used to connect the device to the internet.

To find out the public IP address, we can use the command with curl:

$ curl

The other way to find it is by running the ipinfo command:

$ curl

The api command is also used to display the public IP address:

$ curl

The checkip command method can be used to find the IP address:

$ curl

The last convenient command used to find out the public IP address is:

$ curl

To find the private IP addresses, we can simply use the “ip address” command:

$ ip address

Instead of an address, we can also use “addr” or simply “a” with the IP command:

$ ip addr

$ ip a

The other way to find the IP address is by using the command of ip config, but before it may be you have to install the package of net-tools if you are using Debian-Ubuntu based Linux distributions by the command:

$ sudo apt install net-tools

Once the net-tools are installed, we can find out the ip address using the command:

$ ifconfig -a

The hostname command is used to find out the DNS name but it can also be used to find the IP addresses:

$ hostname -I | awk '{print $1}'

The IP route command can also be used to get the IP address:

$ ip route get | awk '{print $7}'

One of the most common methods used to find the IP address is the nmcli command, in which we can display the device and show its details:

$ nmcli -p device show

We can display the hostname IP simply using the “hostname” command with the “-I” option:

$ hostname -I


The IP address is used to identify the machine on the internet, send, and receive the data on the particular machine. The IP address of every machine is unique and it helps the internet communicate the information among different machines. In this article, we have discussed different commands by which we can find out the ip address of the machine in Linux. We explain the commands for finding both; public and private IP addresses in Linux.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.