Since 2016 · 50,000+ customers · ★ 5.0 on Google Live chatWhatsAppTelegramOpen a ticket
Get started
Linux

How to Check Your IP Address in Ubuntu (Private and Public)

How to check your IP address in Ubuntu by 99RDP

Your Ubuntu machine can have two kinds of IP address. The private (local) IP is the address on your own network, such as 192.168.1.20. The public IP is the address the internet sees, usually your router's or, on a VPS, the server's own address. This guide shows several ways to find both from the terminal and the desktop, how to find IPv6 addresses and your gateway, and how to tell which address to use. The commands work on Ubuntu 20.04, 22.04, 24.04 and 26.04, and on Debian.

Quick answerRun hostname -I for your local IP addresses, or ip a for full details. For your public IP, run curl -4 ifconfig.me.

ip a output on Ubuntu showing loopback and eth0 with IPv4 and IPv6 addresses
Reading ip a output

Method 1: The ip command

ip a

(ip addr show is the long form.) Each interface is listed with its addresses. Look for the inet line under your main interface, for example:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
    inet 203.0.113.10/24 brd 203.0.113.255 scope global eth0
    inet6 2001:db8::10/64 scope global
  • lo with 127.0.0.1 is the loopback interface and can be ignored.
  • Wired interfaces are usually named eth0, ens3 or enp1s0; Wi-Fi is usually wlan0 or wlp2s0.
  • The /24 after the address is the network prefix (subnet mask 255.255.255.0).

To show just IPv4 addresses in a compact form:

ip -4 -brief addr

Method 2: hostname -I

hostname -I

This prints every address assigned to the machine on one line, without the loopback. It is the quickest option for scripts. Note the capital I; lowercase -i shows the address the hostname resolves to, which is often just 127.0.1.1.

Method 3: nmcli (NetworkManager)

nmcli device show | grep -E 'GENERAL.DEVICE|IP4.ADDRESS|IP4.GATEWAY|IP4.DNS'

On desktops and servers that use NetworkManager, this shows the address, gateway and DNS servers per device. On Ubuntu Server, which uses systemd-networkd through Netplan, use networkctl status instead.

Method 4: ifconfig (older systems)

ifconfig is no longer installed by default. If you prefer it:

sudo apt install net-tools
ifconfig

The ip command does everything ifconfig did, so it is worth getting used to.

Method 5: The Ubuntu desktop

  1. Open Settings.
  2. Choose Network (wired) or Wi-Fi.
  3. Click the gear icon next to the connected network. The Details tab shows the IPv4 and IPv6 addresses, default route and DNS.

Find your public IP address

Behind a home or office router, your local address is private and the internet sees the router's public address. Ask an external service from the terminal:

curl -4 ifconfig.me
curl -4 icanhazip.com
dig +short myip.opendns.com @resolver1.opendns.com

Use -6 instead of -4 to get your public IPv6 address. Install curl or dnsutils if a command is missing.

On a VPS or dedicated server, the public IP is normally assigned directly to the network interface, so ip a already shows it. Some cloud providers use a private address on the interface with a public IP mapped by NAT; in that case the curl command shows the public one.

Private vs public IP: home devices share one public IP through the router; a VPS has its own
Private vs public IP

Find your gateway and DNS servers

ip route | grep default
resolvectl status

The first command shows the default gateway (your router or the provider's gateway). resolvectl status shows the DNS servers in use; /etc/resolv.conf usually points to the local resolver 127.0.0.53, so it is not the place to look.

Commands to find each network detail on Ubuntu: private IP, public IP, gateway and DNS servers
Which command for which detail

Private vs public addresses

These ranges are private and only work inside a local network:

  • 10.0.0.0 to 10.255.255.255
  • 172.16.0.0 to 172.31.255.255
  • 192.168.0.0 to 192.168.255.255

Addresses starting with 169.254 mean the machine failed to get an address from DHCP. Anything outside these ranges (and outside 127.x.x.x) is a public address.

Frequently asked questions

What is the command to check the IP address in Ubuntu?

ip a shows all interfaces and addresses. hostname -I shows just the addresses on one line.

Why does ip a show a different IP than websites show?

Your machine has a private address and reaches the internet through a router using NAT. Websites see the router's public IP. Use curl ifconfig.me to see it.

How do I find my IPv6 address in Ubuntu?

Run ip -6 addr and look for addresses with scope global. Addresses starting with fe80 are link-local and only work on the local network.

How do I change my IP address in Ubuntu?

On Ubuntu Server, edit the Netplan file in /etc/netplan/ and run sudo netplan apply. On the desktop, set a manual address in the network settings. On a VPS, only use addresses your provider has assigned to the server.

Nishant Kumar, Sr. Server Engineer at 99RDP
Written byNishant KumarSr. Server Engineer, 99RDP. Part of the team that runs our servers and answers support.
Keep reading

More Linux guides

All Linux guides

Need a server for this?

✓ Setup in minutes✓ Full admin access✓ 7-day refund on new services