How to Find Your IP Address in Linux?

Internet Protocol (IP) is a digital address that connects you to the internet, just as your physical address connects you to the real world. Every user has a unique address so that the internet/user knows where to send information and who is accessing it.

While working on Linux, a system/network administrator must know about the IP address of the user/system.

Considering this, the purpose of this post is to list down the possible methods to find your IP address on Linux. The outline of this post is as follows:

Let’s start this!

Type of IP Address in Linux

The IP address is usually of two types, i.e., Public and Private. A private IP address is usually assigned to the physical device from where you want to access the internet, such as your mobile phone, laptop, or desktop machine. These IP addresses are not understandable by the internet, and this is where your public IP address will help you to do the job.

The public IP addresses can easily be understood by the internet and are usually assigned to the router. When a private IP address requests any information from the internet, that information is first received by the public IP address, which then fetches it and sends it back to the private IP address.

Find Your Private IP Address Using a Terminal

As discussed above, there are two different types of IP addresses, and from them, let’s discuss how you can find the private address using the below methods:

Let’s discuss these methods in detail in the next section.

Using the hostname Command

Your private IP address can be found using the hostname command followed by the ‘-I’ flag, which is:

$ hostname -I

Another way of utilizing this same command to find your private IP address is mentioned below:

Hostname -I | awk ‘{print $1}’

Using the ip Command

The IP command is another way to find your private IP address, and you can do that by typing:

$ ip a

Another way of finding the private IP address using the IP command is by typing:

$ ip addr

Using the nmcli Command

The nmcli command can be used to find your private IP address as it contains all the required information related to your network manager.

$ nmcli -p device show

Using the ifconfig Command

The ifconfig command can be used to configure the network interface where you can add or remove the network address and can view the network information by typing:

$ ifconfig

As you can see in the above image that the ifconfig command failed to execute and it is asking to install the ‘net-tools’ by typing the commands as per your Linux distribution:

$ sudo apt install net-tools

You can install it on Fedora by typing:

$ sudo dnf install net-tools

You can install it on CentOS by typing:

$ sudo yum install net-tools

After that you should be able to execute the ifconfig command by typing:

$ ifconfig

In the next section, we will tell you how you can find your private IP address without the terminal by accessing your network settings.

Find Your Private IP Address Using GUI

The GUI of Linux can also be utilized to get your IP address by going into the network setting as shown in the image below:

Next, select the wired connection settings, which will display the information related to my private IP address as shown below:

Note: I’m using Ubuntu 22.04.1 LTS version on a VMware, which is why it is showing as a wired connection.

This wrap up the detail about finding the private IP address, and next, we will be teaching you how you can find your public IP in detail.

Find Your Public IP Address in Linux Using a Terminal

We will use the curl command to find the public IP address as it can be used to fetch the data information from the websites provided to it. So, some of the most useful websites that can provide you with this information using a curl command are mentioned below:

$ curl checkip.amazonaws.com

The above website primary goal is to provide cloud computing related services but you can also find your public ip address as well. The next website is solely built to provide you with your ip related information and you can use this website to get the information regarding your IP address as well by typing:

$ curl ipinfo.io/ip

This next website that will give you the same information like others is mentioned below:

$ curl ifconfig.me

Find Your Public IP Address using Google Search Bar

Google is a great source to tell you your public IP address where you don’t need to access any website as we did earlier using a curl command. All you need to do is to access the Google search bar by opening any browser and then type ‘what is my IP’. Pressing the enter key after that will give you the information of your public IP address, as shown below:

That’s all from this article.

Conclusion

The IP addresses are of two types, i.e., Public and Private. The private IP address can be found using the “hostname”, “ip”, and “ifconfig” commands in the terminal, or the GUI of Linux can also be used. The Public IP address can also be displayed through the terminal via the curl command or the Google search bar. This post has briefly explained the concept of IP addresses and listed the possible methods to find your IP address on Linux.