Skip to content

How to Find Your IP Address in Linux from the Command Line (Local, Public, Router and Hostname IP)

Updated 5 min read

Updated: 10 October 2026 · Applies to: iproute2 6.1 to 6.17, hostname, BIND 9 tools and curl on Debian 13, Ubuntu 24.04 and AlmaLinux 10; ipconfig on macOS

To find your IP address in the Linux terminal, run ip -4 -br addr or hostname -I. They show the addresses on the server's network interfaces. For the public IP address the internet sees, run curl -4 https://ipinfo.io/ip. The commands are the same on Ubuntu, Debian, AlmaLinux, Rocky Linux and other distributions.

ip -4 -br addr                 # addresses on each network interface
hostname -I                    # the same, on one line
curl -4 https://ipinfo.io/ip   # your public IPv4 address
ip route show default          # your router (default gateway)
getent hosts example.com       # the IP address of a hostname

We ran every command below in containers on our test server. Container addresses (10.88.x.x) are shown as we got them; our public address is replaced with 203.0.113.10.

1. Show the IP addresses of your Linux server

$ ip -4 -br addr
lo               UNKNOWN        127.0.0.1/8
eth0@if776       UP             10.88.2.145/16

Each line shows the interface, its state and its address with the prefix length (/16 is the subnet mask 255.255.0.0). Ignore lo: 127.0.0.1 is the loopback address every Linux system has. Your main interface may be called eth0, ens3 or enp1s0; the @if776 part appears only inside containers.

  • All details (MAC address, broadcast, IPv6): ip addr or the short form ip a.
  • IPv6 only: ip -6 -br addr. An address starting with fe80: is link-local and not reachable from the internet.
  • One interface: ip -4 addr show eth0
  • Just the address, for scripts:
    $ ip -4 -o addr show scope global | awk '{print $4}'
    10.88.2.145/16
  • hostname -I prints every address of the host on one line, without the loopback:
    $ hostname -I
    10.88.2.145

ip: command not found? Minimal images and containers often leave it out. It was missing in the Debian 13, Ubuntu 24.04 and AlmaLinux 10 images we used. Install iproute2 (Debian, Ubuntu) or iproute (AlmaLinux, Rocky Linux, RHEL). hostname was installed in all three.

Looking for ipconfig? That is the Windows command. The old Unix equivalent is ifconfig from the net-tools package, which was missing in our AlmaLinux 10 and Ubuntu 24.04 images. It still works once installed (ifconfig eth0), but ip is its replacement: see ifconfig vs ip.

2. Find your public (external) IP address

On most VPS and dedicated servers the public address is set on the interface itself, so step 1 already shows it. If step 1 shows only a private address (starting with 10., 172.16. to 172.31. or 192.168.), the machine sits behind a router or NAT, as on a home or office network. Ask a service on the internet which address it sees:

$ curl -4 https://ipinfo.io/ip
203.0.113.10

All of these returned the same address in our test:

curl -4 https://ifconfig.me
curl -4 https://icanhazip.com
wget -qO- https://ipinfo.io/ip
dig +short myip.opendns.com @resolver1.opendns.com
dig +short txt ch whoami.cloudflare @1.1.1.1
dig +short TXT o-o.myaddr.l.google.com @ns1.google.com

The dig versions ask a DNS server instead of a website; the last two print the address in quotes. curl https://ipinfo.io (without /ip) returns more IP information as JSON: the reverse hostname, city, country and the network that owns the address. Use curl -6 instead of -4 to see your public IPv6 address, if you have one. These are free third-party services: fine for a quick check, but do not build anything important on them.

3. Find your router (default gateway) IP address

$ ip route show default
default via 10.88.0.1 dev eth0 proto static metric 100

The address after via is the gateway, which is your router on a home or office network. To see which gateway and which of your own addresses Linux uses to reach a particular address:

$ ip route get 1.1.1.1
1.1.1.1 via 10.88.0.1 dev eth0 src 10.88.2.145 uid 0

The older route -n and netstat -rn (both from net-tools) show the same gateway in the Gateway column of the line with the UG flags. The router's own public (WAN) address is the one step 2 shows.

4. Get the IP address of a hostname

$ getent hosts example.com
2606:4700:10::6814:179a example.com
2606:4700:10::ac42:93f3 example.com

$ dig +short example.com
172.66.147.243
104.20.23.154
  • getent hosts resolves the name the way your applications do, including entries in /etc/hosts. When a name has IPv6 addresses it showed only those, as above; use getent ahostsv4 example.com for the IPv4 addresses.
  • dig +short, host example.com and nslookup example.com ask DNS directly. On Debian and Ubuntu they come in bind9-dnsutils (also installable as dnsutils), on AlmaLinux and Rocky Linux in bind-utils. See DNS lookup commands: dig, nslookup and host.
  • ping -c1 example.com also prints the address it resolved, on its first line.
  • hostname -i shows the address of the machine's own hostname. It works only if that name resolves, usually through /etc/hosts.

5. macOS and other Unix systems

  • macOS: ipconfig getifaddr en0 prints the IPv4 address of interface en0, and ipconfig getoption en0 router prints the router address (from the macOS ipconfig manual). ifconfig lists all interfaces.
  • BSD and other Unix systems: use ifconfig; ip is Linux only.
  • The curl and dig commands from step 2 work the same on macOS, which includes curl.

On a Ucartz VPS or dedicated server

Your server's addresses are also listed in the client area under the service. See how to find your server IP address and server location. If you have additional IP addresses, test that every additional IP works. For more ip examples (routes, ARP, adding addresses), see the ip command cheat sheet.

Official documentation: ip-address manual and hostname manual.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket