Linux: Get IP Address
We just logged into a Linux machine, and all we have is a command prompt like this:
How do we find all the IP addresses of this Linux server running in the cloud, virtual machine running on our own computer, or whatever it might be?
Linux Command to Display IP Addresses
No matter if we're running Ubuntu, Debian, something from the Red Hat family (or any other popular Linux distribution) there should be a command called ip
that we can use.
To see all IP addresses of a Linux machine, we can run a command like this:
ip -c address
-c
is an option we pass to the ip
command to make it use special colors to highlight important parts of the output. It simply makes it easier to spot our IP addresses (since the output from this command is a bit crowded and messy).
If we're lucky, we'll get relatively short output like this:
For non-English speakers, it might be hard to remember the correct spelling of address
. So a shorter version of this command is:
ip -c a
How to Interpret the Output of the "ip" Command
There's a lot of information displayed in an ip
command. And some Linux machines might have multiple network cards, and multiple IP addresses. Even multiple IP addresses for a single network card. Which means the output could be even longer than what we saw.
How do we extract the stuff we need?
In our output, we can immediately see the IP address we're looking for.
Which is 10.11.12.14
. An IP address associated with a network device called enp1s0
on this machine.
So what's with the device above, labeled as number 1
and called lo
; with an IP address of 127.0.0.1
? That's the loopback interface. A sort of "fake" network device. Used by many operating systems to allow programs to connect back (loop back) to the same computer.
For example, we might have the Nginx web server application connect back to the same computer to get some data from a local database. And it would use the IP 127.0.0.1
to connect to the MariaDB application running on this same machine.
Otherwise said, we'll see this lo
interface on almost all Linux machines. And we can ignore it. Our focus should be on the other interfaces.
Now notice that in the output of the ip
command we have something called inet
and something called inet6
:
inet
shows an IPv4 address. In this case,10.11.12.14
.inet6
shows an IPv6 address. In this case,fe80::5054:ff:fe05:4cbd
.
IPv4 is the old protocol for IP addresses. But it's still heavily used on the Internet today. Or, at least, was used a lot back in 2025 (in case you're reading this far into the future).
IPv6 is the new protocol, with a different notation for IP addresses. And it will be used a lot more in the future. At a point, IPv4 might even be phased out entirely, in favor of IPv6.
Either way, that's how easy it is to get the IP addresses used by a Linux machine. Now for the tricky part.
How to Find the Private and Public IP Address of a Linux Machine
In networking terms, we sometimes call an IP private, or public.
We usually call it a private IP address (or internal IP address) if it's only used on a "closed" network (unreachable from the Internet, directly).
For example, a smartphone at home, and a smart TV, might get two private IP addresses, like 192.168.0.5
and 192.168.0.6
. And they can "talk" to each other through these IP addresses, with the help of a home router.
No one from the Internet should be able to reach that smartphone (directly) on the private IP address 192.168.0.5
.
However, data from YouTube still reaches that phone, somehow. That's because the router has a public IP address (external IP) like 203.0.113.15
. That's reachable from the Internet, so YouTube can send data to that IP address. And then the router forwards it to the smartphone at home.
Long story short:
- Private IP addresses for closed, internal networks.
- Public IP addresses so that devices on the Internet can talk (directly) to each other.
Things can sometimes diverge from these "rules," but that's the gist of it. Either way, back to our purpose.
From this output, how do we know if this is a private, or public IP address?
Hint: 10.11.12.14
is a private (internal) IP address.
There's a convention to have private / internal IP addresses begin either with 10.
or with 192.168.
. There might be exceptions to this rule, in some cases, but almost always, anything that begins with 10.
or 192.168.
will be a private / internal IP. Also, addresses between 172.16.
to 172.31.
are private IPs.
So how can we get the public IP used by a Linux machine? A simple way is to connect to some special websites that have just one purpose: To return our external / public IP address.
We'll need a command called curl
to do this. Which is installed on most Linux machines, but not all of them. To make sure the command is installed, we can run this:
curl -V
If we get output showing version information, we're good to go, we have it installed.
If we get a "command not found" error, then we need to install it.
To install curl
on Ubuntu / Debian systems, or anything derived from this family (that uses .deb
software packages), we can run:
sudo apt install curl
To install it on Red Hat systems, or anything from this family that uses .rpm
packages, we can run:
sudo dnf install curl
Then to get the public IP address of a Linux machine, we can run any of these commands:
curl icanhazip.com
curl checkip.amazonaws.com
curl ifconfig.me
We'll get output like this:
Which, in this case, shows us that our public IP address is 35.188.139.128
.
It's worth noting that for some Linux servers running in the cloud, the ip -c address
command will show us the external IP as well. But it doesn't hurt to double check with one of the curl
commands above.
If both ip -c address
and curl icanhazip.com
show us an IP address like 35.188.139.128
, then that's the external IP of our Linux server.
Conclusion
We hope you found this blog interesting. And if you need to tweak network settings on your Linux machine, change IP addresses, or simply learn more about Linux, check out this course:

We'll see you in the next blog!