How to Find Public and Private IP on Linux

Did you know that there are two different types of IP addresses on a device. The first is Public IP, which is what it is used to surf the internet. And the second is Private IP, which can only be used for local network management.

A device can get the same Public IP when connecting on the same router. But not with Private IP, even if connecting on the same router, the IP obtained will be unique or different.

On Linux operating system, there are many ways to find out Public and Private IP, all of them can be done from Terminal. And here is the procedure.

Knowing Private IP on Linux

There are many commands that can be used to find out. One of them that certainly can be applied to all Linux OS is the command ifconfig. So now please open a terminal, and then type the command below.

ifconfig -a

Knowing Private IP Address on Linux

The Private IP Address is located in the inet addr. It usually starts with 172 or 192, depending on the router’s network settings. Underneath it also appears the localhost IP address, which is, which has almost the same use as Private IP.

In addition, you can also use some of the commands below as an alternative:

  • ip addr

  • hostname -I | awk ‘{print $1}’

  • ip route get | awk ‘{print $7}’

Knowing Public IP on Linux

As long as the device has internet access, it should be able to see the Public IP address easily. Be it through the browser or even through the terminal though. Here is the command:


Knowing the Public IP Address on Linux

Instantly the IP address will be directly displayed on the terminal. So the above command uses CURL to access the website ifconfig.meas for similar websites that can do the same thing, namely

In addition to using cURL, you can also use the command DIG to find out the Public IP address. Please copy the command below:

dig +short

Also read: Changing IP Address Through Command Prompt

Now you have understood about knowing the IP address on Linux. However, if you have other problems or questions, don’t hesitate to comment in the column provided below this article.

Hopefully useful and good luck