How To Get Your Public & Private IP Address on Linux
How to get in several ways through the terminal the IP address, already private or public in Linux.
Our devices connected to the Internet have an IP, which is the credential that you have before the world.
Public: It is the address with which we go online, which has a web server or a service that is offered on the web.
Private: It is an address for the local or private network, this address is not the one seen on the Internet, it is public.
Sometimes we need to know the IP address of our machine or our router, so in this tutorial, we will see how to obtain the IP address in Linux, for this, we will use the Ubuntu operating system.
Get Private IP Address in Linux
We start by obtaining our private IP address, for this, we have several options, here we will see some.
The first sure that almost everyone knows, we execute the following command:
Next, we leave a capture of the output of the command:
We can appreciate that our IPv4 address is 192.168.0.104. And that just below this address we have Inet6 address, for IPv6. The interface refers to localhost.
Another possibility that we have is to execute the following command:
Then you can see the output:
Nothing complex, as you can see.
You can also get this information in a graphical way, you can go to “System settings” or “Settings” and go to Network, you will see something similar to the following image:
Get Public IP Address in Linux
We went to get the public IP address, we also have several ways, let's see some.
For the first option that we propose we will need curl, if you do not have it installed, execute the following command:
sudo apt-get install curl
Once we have curl installed, we run the following in the terminal:
We will see the following output:
Another option to obtain the same information is by executing the following command:
wget -qO- ifconfig.me/ip
With this tutorial we have been able to verify how to get the IP address, whether public or private, it is very easy, requires little knowledge and also is not a task that takes us a long time.