How to check your IP address in Linux

Find a Linux machine’s private, public and IPv6 addresses with ip addr, hostname -I or curl, and know which one to use for SSH, DNS and firewalls.

5–8 minutes
Network switch with many blue patch cables

To check your IP addressIP address The number address of a device on the internet, like 203.0.113.10. Computers use it to find each other, the way post uses street addresses. More about IP address → in Linux, run ip addr for the addresses on the machine itself, or curl -4 icanhazip.com for the public address the internet sees. This guide is for anyone working on a Linux server or PC who needs the right IP address for an SSHSSH A secure way to type commands on a server from your own computer, as if you were sitting at it. More about SSH → login, a DNS record or a firewall rule.

Run **ip -br addr to list every network interface and its IP addresses in one short table, or hostname -I for just the addresses. These show the addresses configured on the machine. If the machine sits behind a router, its public address is different: find it with curl -4 icanhazip.com**. The ifconfig command is older and often not installed.

Which IP address do you need?

A Linux machine usually has more than one IP address, so first decide which one you are after.

AddressWhat it isExampleHow to find it
LoopbackThe machine talking to itself127.0.0.1Always the same, no need to check
Private (local)Used inside a home, office or cloud network192.168.1.20, 10.0.0.5ip addr
PublicThe address the rest of the internet sees203.0.113.10ip addr on most VPS servers, otherwise curl
IPv6The newer, longer address format2001:db8::10ip -6 addr

On a typical VPSVPS A private slice of a powerful server, with its own guaranteed share of memory and processing and full control, at a fraction of the price of a whole machine. More about VPS → or dedicated server, the public address is attached directly to the server’s network card, so ip addr shows it. On a home PC, a Raspberry Pi or a laptop on office Wi-Fi, the machine only has a private address and the router translates it to a public one (a process called NAT). In that case ip addr will never show the public address, and you need to ask an outside service.

Some cloud platforms also use NAT: the server’s network card holds a private address such as 10.0.0.5, and the provider maps a public address to it. If ip addr only shows a private address on a cloud server, check the public address in the provider’s control panelControl panel A website you log into to manage your hosting with buttons and forms, instead of typing commands. cPanel and Plesk are the common ones. More about Control panel → or with the curl method below.

Check the IP address with the ip command

The ip command is part of the iproute2 package and is installed on every current distribution, including Ubuntu 22.04 and 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9. You do not need root to read addresses.

1. Get a short summary

ip -br addr

The -br option means brief: one line per interface. The output looks like this:

lo               UNKNOWN        127.0.0.1/8 ::1/128
eth0             UP             203.0.113.10/24 2001:db8::10/64 fe80::5054:ff:fe12:3456/64

Each line shows the interface name, whether it is up, and its addresses. The number after the slash is the network size (the prefix length), not part of the address itself: the IP address here is 203.0.113.10.

Interface names vary. Older systems and many cloud servers use eth0; newer systems often use names such as ens3, enp0s3 or enp1s0. Wi-Fi usually starts with wl, for example wlp2s0. Ignore lo, which is the loopback interface, and docker0 or names starting with veth or br-, which belong to Docker containers and bridges.

2. See the full details

ip addr show

This is the long form (ip a is a common shortcut). Look for lines starting with inet (IPv4) and inet6 (IPv6) under each interface:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
    inet 203.0.113.10/24 brd 203.0.113.255 scope global eth0
    inet6 2001:db8::10/64 scope global
    inet6 fe80::5054:ff:fe12:3456/64 scope link

The word scope global marks an address that can be used beyond this machine. scope link marks an IPv6 link-local address starting with fe80:, which only works on the local network segment and is not the one you want for DNSDNS The internet’s phone book. It turns a name people can remember, like example.com, into the number address computers use to find the server. More about DNS → or SSH.

3. Show only IPv4 or IPv6, or one interface

ip -4 addr show
ip -6 addr show
ip addr show dev eth0

Replace eth0 with your own interface name from step 1.

4. Find the address used for outgoing traffic

When a server has several addresses, this shows which one Linux actually uses to reach the internet:

ip route get 1.1.1.1

The output includes src 203.0.113.10, the source address the server will use. The command only looks up the route; it does not send anything to 1.1.1.1.

Quicker ways: hostname -I and ifconfig

For a plain list of addresses without interface names, run:

hostname -I

It prints every configured address except loopback and IPv6 link-local addresses, separated by spaces, for example 203.0.113.10 172.17.0.1 2001:db8::10. The order is not guaranteed, so do not assume the first address is the main one. Here 172.17.0.1 belongs to Docker, not to the server’s real network.

You will also see ifconfig in older guides. It comes from the net-tools package, which has been replaced by iproute2 and is often missing on fresh installs, giving ifconfig: command not found. Use ip addr instead. If you really need ifconfig, install net-tools with sudo apt install net-tools on Ubuntu and Debian, or sudo dnf install net-tools on AlmaLinux and Rocky Linux.

Check your public IP address from the terminal

To see the address the internet sees, ask an outside service to echo it back:

curl -4 icanhazip.com
curl -6 icanhazip.com

The -4 and -6 options force IPv4 or IPv6. If the IPv6 command fails or hangs, the machine has no working IPv6 connection, which is common on home networks.

If curl is not installed, use DNS instead. This asks the OpenDNS resolver to return the address your request came from:

dig +short myip.opendns.com @resolver1.opendns.com

dig is in the dnsutils package on Ubuntu and Debian (bind9-dnsutils on newer releases) and in bind-utils on AlmaLinux and Rocky Linux. The DNS lookup guide explains how to read its output.

If you are on a VPN or behind a proxy, these services report the VPN or proxy address, not your own connection.

What to do with the address

  • SSH: use the public address (or a domain pointing at it) to connect to the server with SSH, for example ssh exampleco@203.0.113.10.
  • DNS: put the public IPv4 address in your domain’s A recordA record The line in a domain’s settings that says which server’s address to send visitors to. Like a forwarding address card for your website. More about A record → and the global IPv6 address in its AAAA record. Never use a private address in public DNS.
  • FirewallFirewall A gatekeeper that decides which connections are allowed into a server and blocks the rest. More about Firewall → rules: when you allow your own office or home address through a firewall, use the public address of that connection, found with the curl method on a machine there.
  • Local network: to reach a Raspberry Pi or test server from another device at home, use its private address, such as 192.168.1.20.

Home and some office connections get a dynamic public address that can change. If a firewall rule or DNS record suddenly stops working, check whether the address has changed.

Common problems

SymptomCauseFix
ifconfig: command not foundnet-tools is not installedUse ip addr, or install net-tools
ip addr shows only 192.168.x.x or 10.x.x.xThe machine is behind NATUse curl -4 icanhazip.com for the public address
curl shows a different address from ip addrNAT, a VPN or a proxy is in the pathUse the curl result for anything on the internet
An interface shows DOWN and no inet lineThe network is not connected or not configuredCheck the cable or Wi-Fi, then the network configuration
hostname -I lists many addressesDocker, VPN or bridge interfaces add their ownUse ip -br addr to see which address belongs to which interface
Only an fe80: IPv6 address appearsThe network has no IPv6 serviceUse IPv4, or enable IPv6 with your host or ISP

Official documentation

Get the next guide

One email when there is something worth reading: new guides, errors going around, and hosting changes that affect your site.

No tracking pixels, and one click to leave.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.