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 the public IP that 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 to the same router. But not with private IP, even if the connection is made through the same router, the obtained IP will be unique or otherwise.
There are many ways to find out the public and private IP on the Linux operating system. All can be done from the terminal. And here is the procedure.

Know private IP under Linux
There are many commands that can be used to find out. One of them that surely can be applied to all Linux operating systems is the command ifconfig. Now please open a terminal and enter the following command.
ifconfig -a
The private IP address is in the inet address. It usually starts with 172 or 192, depending on the router’s network settings. The localhost IP address 127.0.0.1, which has almost the same usage as Private IP, also appears below this.
In addition, you can alternatively use some of the following commands:
IP address
Hostname -I | awk ‘{print $ 1}’
Get IP route 1.2.3.4 | awk ‘{print $ 7}’
Know public IP on Linux
As long as the device has internet access, it should be able to see the public IP address without any problems. Be it via the browser or even via the terminal. Here is the command:
curl ifconfig.me
The IP address is immediately displayed directly on the terminal. So the above command uses CURL to access the website ifconfig.me, as for similar websites that can do the same thing, viz ident.me.
In addition to using cURL, you can also use the command DIG to find out the public IP address. Please copy the following command:
dig +short myip.opendns.com @resolver1.opendns.com
Also read: Changing the IP Address Using the Command Prompt
Now you have understood how to know the IP address under Linux. However, if you have any other problems or questions, don’t hesitate to leave a comment in the column below this article.
Hopefully useful and good luck