How to Find Your IP Address on Ubuntu Linux
Find the private and public IP address of an Ubuntu machine from the terminal or the desktop, plus the gateway, the DNS servers and the MAC address.
3 min readBy Smita
Reviewed by the AmazingRDP technical team

Need a machine with a public IP address of its own? A Linux VPS has one. See Linux VPS from $6.99
"My IP address" can mean two things. The private address is the one your machine has inside the local network. The public address is the one the internet sees, which at home belongs to the router. Ubuntu shows the first directly; the second you ask an outside service for.
The quick answers
hostname -I
curl -4 ifconfig.me
The first prints the machine's own addresses. The second prints the public one.
The private address, in detail
ip a
Short for ip addr show. Each network interface gets a block. Look for the line starting with inet under the interface that is in use:
lois the machine talking to itself, always127.0.0.1. Ignore it.eth0,ens3,enp0s3and similar are wired interfaces.wlan0,wlp2s0and similar are Wi-Fi.inet 192.168.1.25/24is the IPv4 address;inet6lines are IPv6.
Shorter views:
ip -4 -br addr
ip -br addr show eth0
-br prints one line per interface, -4 leaves IPv6 out.
Which address is used for the internet? On a machine with several interfaces:
ip route get 1.1.1.1
The address after src is the one.
The public address
curl -4 ifconfig.me
curl -4 icanhazip.com
curl https://api.ipify.org
Each asks a website to report the address it sees. If curl is missing: sudo apt install curl. Without it, DNS can answer too:
dig +short myip.opendns.com @resolver1.opendns.com
Private or public: how to tell
| Range | Kind |
|---|---|
| 10.x.x.x | Private |
| 172.16.x.x to 172.31.x.x | Private |
| 192.168.x.x | Private |
| 100.64.x.x to 100.127.x.x | Shared by an internet provider among customers |
| 169.254.x.x | Self-assigned: the machine asked for an address and got no answer |
| Anything else | Public |
On a home PC the two commands at the top give different answers. On a VPS or dedicated server they usually match, because the public address sits directly on the machine.
On the desktop
Open Settings. For Wi-Fi, go to Wi-Fi and click the gear next to the connected network. For cable, go to Network and click the gear next to Wired. The Details tab shows the IPv4 and IPv6 addresses, the gateway and the DNS servers.
Gateway, DNS and MAC address
ip route | grep default
resolvectl status | grep "DNS Servers"
ip -br link
- The first shows the gateway, which is your router's address.
- The second shows the DNS servers in use: see DNS in Linux.
- The third shows each interface's MAC address, the hardware address of the network card.
With NetworkManager, one command shows all of it for one interface:
nmcli device show eth0
What about ifconfig?
Older guides use ifconfig. Ubuntu no longer installs it. The ip command replaces it; if you want the old one anyway: sudo apt install net-tools.
If there is no address
- The interface shows
DOWN: the cable is out or Wi-Fi is off. - An address starting with
169.254: no answer from the router's DHCP service. - After changing network settings, restart networking: see how to restart the network in Ubuntu.
Keep the address from changing
A private address handed out by the router can change. For a machine others must find, set a fixed one: see how to set a static IP address in Ubuntu. The public address of a home line can change too; a server has a fixed one, which is one reason to host there. See our Linux VPS plans.
Questions
How do I find my IP address in the Ubuntu terminal?
Run hostname -I or ip a for the private address and curl -4 ifconfig.me for the public one.
What is the difference between private and public IP?
The private address works inside your local network. The public address is what the internet sees, usually your router's.
Why does ifconfig not work on Ubuntu?
It is no longer installed by default. Use ip a, or install the package net-tools.
How do I find my default gateway on Ubuntu?
Run ip route | grep default. The address after "via" is the gateway.