How to Find Your IP Address in Linux

https://static1.makeuseofimages.com/wordpress/wp-content/uploads/2021/05/NAT-working-principle-e1621422180626.png

An IP address is a numerical label that uniquely identifies devices on a network. There are two types of IP addresses, public and private. A private address is used for labeling devices within an internal network and is globally unreachable.

On the contrary, public IPs are globally routable and are important for connecting to the internet. This guide shows how easy it is for Linux users to get IP address information on their computers.

How Do IP Addresses Work?

You need to know a few things before learning how to find the IP address of your Linux machine. When connected to the home network, all your devices have unique private IPs. However, you can’t connect to the world wide web via private addresses. You’re going to need a public IP to do so.


Your router assigns you the public IP when you make web requests from one of your devices. There’s an entire mechanism called Network Address Translation (NAT) to do this. NAT works by substituting the private address from the IP packet header with a globally accessible public IP.

Find Private IP Address of a Linux System

According to RFC 1918 (Address Allocation for Private Internets), private networks can have IPs within the ranges given below. Here X represents any number between 0 to 255.

  • 10.X.X.X – 10.X.X.X
  • 172.16.X.X – 172.31.X.X
  • 192.168.X.X – 192.168.X.X

There are several ways to check private IP addresses in Linux. The easiest of them is the Linux ip addr command.

ip -4 addr

This command displays both the loopback address (127.0.0.1) and the actual private address of the machine.


Use the following command on Linux if you want to get only the IP address of the system.

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

Alternatively, you can use the hostname command on Linux to get the IP address of a host.

hostname -I

You can also use the nmcli utility to get the private IP address of your interface. It’s a console-based program for managing the network manager.

nmcli -p device show

Find Public IP Address of Linux Systems

As NAT is responsible for assigning the public IP for your system, you can’t get it directly from the device. Instead, you need to send a web request to an external system and retrieve the IP address from the response.

Use one of the following Linux commands to get your public IP address from the command line.

dig +short myip.opendns.com @resolver1.opendns.com
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
curl https://ifconfig.me ; echo
curl https://ipinfo.io/ip ; echo
wget -qO- api.ipify.org ; echo
wget -qO- https://ipecho.net/plain ; echo

However, the simplest way for Linux users to get the public IP address is via a simple Google search. All you need to do is type "what is my ip" in a new search, and Google will tell you the public IP address.

Related: How to Find the Public IP Address on a Linux System

How to Hide IP Address on Linux?

Since websites can track users and geolocation using IP addresses, many people choose to hide their IP. There are several ways to hide your IP address on Linux.

  • VPN: A VPN (Virtual Private Network) acts as an intermediary between your device and the website you want to visit. They mask your IP by making it look like the requests have originated from the VPN server instead of your machine. Apart from masking IP, there are other reasons for using VPNs as well, including data encryption and bypassing censorship.
  • Tor: It’s a secure network consisting of thousands of nodes run by volunteers all over the world. Tor provides anonymity by relaying traffic through many anonymous nodes. You can use the free Tor browser for hiding IP on Linux.
  • Proxy: Proxy servers make it look like your web requests are originating from their system. They don’t encrypt data and are often unreliable compared to VPNs or Tor.

Get IP Address on Linux Instantly

As illustrated throughout this guide, it’s very simple for Linux users to get their IP addresses. You can find both the private and public IP addresses of your system using the methods described above.

But what if you want to find your phone’s IP address? Luckily, it’s as easy as finding the IP of your computer, if not easier.

MUO – Feed