How to Get Your IP Address on Linux: Commands, GUI and Public IP

Updated

Short answer

Open a terminal and run ip addr (short: ip a). The inet line under your Ethernet or Wi-Fi interface, such as inet 192.168.1.23/24, is your local IP address; hostname -I prints all addresses on one line. On a home or office network, both show the private IPv4 address, not the public IP that websites see, which sits on your router.

On this page

On Ubuntu, Debian, Fedora, Mint, Kali or Arch, run ip a in a terminal to see the local (private) IP address your router assigned. The box below shows your public IP, the one websites see. The page also covers the GNOME and KDE settings screens, scripts, servers and how to change the address.

Your public IP address

216.73.216.128

Location
Columbus, Ohio, United States
Provider
Anthropic, PBC (AS16509)
Time zone
America/New_York (UTC−4)
Coordinates
39.96, -83.00

This is the address websites see, and the location is an estimate that can be off by a city or more. Your device's local IP (often 192.168.x.x) is a different one and only works inside your network.

Commands to get your IP address on Linux

TaskCommandShows
All interfaces and addressesip aLocal IPv4 and IPv6 per interface
One line per interfaceip -br aInterface, state, addresses
IPv4 on one interfaceip -4 addr show dev wlp2s0That interface only
All addresses on one linehostname -ILocal IPs, no loopback
Address used for the internetip route get 1.1.1.1src = your IP, via = router
Default gateway (router)ip routeLine starting with default via
NetworkManager view, with DNSnmcli device showIP4.ADDRESS, IP4.GATEWAY, IP4.DNS
Public IPdig -4 +short myip.opendns.com @resolver1.opendns.comThe address websites see

An address in 10.0.0.0–10.255.255.255, 172.16.0.0–172.31.255.255 or 192.168.0.0–192.168.255.255 is private. Local IP address explained covers what that means for port forwarding and remote access.

How to read the ip a output

ip a is short for ip address show, from the iproute2 package that current distributions install by default. The ip-address(8) manual page documents all options. Typical output on an Ubuntu laptop on Wi-Fi:

Text
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp3s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 00:00:5e:00:53:01 brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:00:5e:00:53:02 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.23/24 brd 192.168.1.255 scope global dynamic noprefixroute wlp2s0
       valid_lft 85841sec preferred_lft 85841sec
    inet6 2001:db8:1234:5678:a1b2:c3d4:e5f6:7890/64 scope global temporary dynamic
       valid_lft 86157sec preferred_lft 14157sec
    inet6 fe80::200:5eff:fe00:5302/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 00:00:5e:00:53:03 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

What the parts mean:

  • inet 192.168.1.23/24: the IPv4 address. /24 is the prefix length (subnet mask 255.255.255.0), not part of the address.
  • inet6: an IPv6 address. Global IPv6 addresses are usually public; temporary marks the privacy address used for outgoing connections.
  • scope global: valid beyond this machine. scope link (fe80::) works only on the local segment, scope host (127.0.0.1) only inside this computer.
  • dynamic with a counting valid_lft: the address came from DHCP or IPv6 autoconfiguration. forever usually means a static address.
  • state UP / LOWER_UP: the interface is connected. NO-CARRIER means no cable or link.
  • link/ether: the MAC address, not an IP.

Common interface names:

NameWhat it is
loLoopback; 127.0.0.1 always points to this computer
enp3s0, eno1, ens18, eth0Ethernet; eth0 in VMs, containers and older systems
wlp2s0, wlan0Wi-Fi
docker0, br-…, veth…Docker’s bridge networks and container links
virbr0libvirt/KVM virtual network, 192.168.122.1 by default
tun0, wg0VPN tunnels (OpenVPN, WireGuard)

Show only the address you need

Shell
ip -br a                          # one line per interface
ip -4 -br a show scope global     # IPv4 only, no loopback
ip -4 addr show dev wlp2s0        # one interface (use your name from ip a)
ip -6 addr show scope global      # public-capable IPv6 addresses

Find the address Linux actually uses for the internet

A machine with Docker, a VPN or both Wi-Fi and Ethernet has several addresses. ip route get asks the kernel which source address and route it would use for a destination, without sending packets.

Shell
ip route get 1.1.1.1
Text
1.1.1.1 via 192.168.1.1 dev wlp2s0 src 192.168.1.23 uid 1000
    cache

src is the IP your computer uses toward the internet, dev the interface, and via your router. For the router’s admin page and default addresses, see how to find your router’s IP address.

hostname -I vs. hostname -i

According to the hostname(1) manual page:

  • hostname -I (capital I, --all-ip-addresses) lists all configured addresses on all interfaces, without loopback and IPv6 link-local addresses. It does not depend on name resolution.
  • hostname -i (lowercase, --ip-address) resolves the host name. On Debian and Ubuntu it often prints 127.0.1.1 from /etc/hosts. The manual says to avoid it.

Warning

The manual also says not to assume anything about the order of the hostname -I output, so hostname -I | awk '{print $1}' can return a Docker or VPN address instead of your LAN IP. On Arch Linux, hostname comes from a different package that may not support -I; use ip there.

ifconfig, nmcli and other ipconfig equivalents

Linux has no ipconfig. These commands replace it:

WindowsLinux
ipconfigip a
ipconfig /allip a plus nmcli device show or resolvectl status (DNS)
Default Gatewayip route
ipconfig /release + /renewsudo nmcli connection up "<name>" (NetworkManager) or sudo networkctl renew <interface> (systemd-networkd)
ipconfig /flushdnsresolvectl flush-caches

ifconfig comes from the deprecated net-tools package, which Ubuntu and many other current installs leave out (“command not found”). sudo apt install net-tools adds it, but ip shows the same and more.

On desktop distributions and on Fedora and RHEL, NetworkManager manages the connection. nmcli shows its view:

Shell
nmcli device status                         # interfaces and their connection names
nmcli device show wlp2s0                    # IP4.ADDRESS, IP4.GATEWAY, IP4.DNS
nmcli -g IP4.ADDRESS device show wlp2s0     # only the address, e.g. 192.168.1.23/24

Find your IP address in Ubuntu Settings (GNOME) and KDE Plasma

These steps show the local IP on Ubuntu 26.04 LTS and 24.04 LTS, Fedora Workstation and other GNOME desktops:

  1. Open Settings (system menu at the top right, then the gear icon, or search for Settings).
  2. Click Network for a cable connection or Wi-Fi for wireless.
  3. Click the gear icon next to the active connection.
  4. On the Details tab, read IPv4 Address, IPv6 Address and Default Route (your router).

On KDE Plasma 6 (Kubuntu, Fedora KDE, KDE neon):

  1. Click the network icon in the system tray.
  2. Click your connected network to expand it.
  3. Open the Details tab and read IPv4 Address.

Get your public IP address from the Linux command line

Behind a home router, your interfaces hold only private IPv4 addresses, so ip a can’t show the public IPv4. Ask a server which address your request came from instead. The DNS method needs only dig (bind9-dnsutils on Debian and Ubuntu, bind-utils on Fedora):

Shell
dig -4 +short myip.opendns.com @resolver1.opendns.com

The -4 matters on networks with IPv6: without it, dig may ask OpenDNS over IPv6, which returns no IPv4 address, and the command prints nothing.

Any web service that echoes your address works with curl too. To get the public IP with its location, ISP and time zone, call our IP lookup API: without an ip parameter, it answers for the address the request comes from. Set IPLOOKUPAPI_KEY to a free API key first:

Shell
curl -s -H "apikey: $IPLOOKUPAPI_KEY" \
  "https://api.iplookupapi.com/v1/info?fields=ip,location.city.name,location.country.name,connection.isp,timezone.id" \
  | jq '.data'

Use jq -r '.data.ip' instead of jq '.data' to print only the address; curl -4 or curl -6 forces IPv4 or IPv6. The info endpoint documentation lists every field. IP location is an estimate, city-level at best; what an IP address tells you explains the limits.

Get just the IP address in a script

Use one of these instead of parsing hostname -I:

Shell
# Known interface: IPv4 without the /24
IP=$(ip -4 -o addr show dev eth0 | awk '{print $4}' | cut -d/ -f1)

# The address used for outgoing traffic (no interface name needed)
IP=$(ip route get 1.1.1.1 | awk '{for (i = 1; i < NF; i++) if ($i == "src") {print $(i + 1); exit}}')

# Same with JSON output and jq
IP=$(ip -j route get 1.1.1.1 | jq -r '.[0].prefsrc')

echo "$IP"

The old one-liner ip route get 1 | awk '{print $NF}' breaks on current iproute2: the line now ends with uid 1000, so it prints the user ID. Match the src keyword as above. For IPv6, use ip -6 route get 2606:4700:4700::1111.

IP addresses on servers, cloud VMs, Docker and WSL

Cloud VMs

On most cloud VMs, ip a shows only the private address of the virtual network. The provider maps the public (elastic or external) IP to it at its network edge, so it never appears on the interface. Find it in the provider’s console, its instance metadata service (an internal HTTP endpoint, often at 169.254.169.254) or with the public-IP commands above. Apps behind a load balancer or CDN see the proxy’s address; real client IP behind proxies shows how to get the visitor’s.

Docker containers

Each container gets an address on a Docker network, 172.17.0.0/16 for the default bridge. From the host:

Shell
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mycontainer

Only the host and containers on the same network reach that address. Other machines use published ports on the host’s IP.

WSL on Windows

In the default NAT mode, WSL 2 has its own virtual network address (often 172.x), separate from the Windows IP. Run hostname -I inside WSL, or wsl hostname -I from PowerShell. With networkingMode=mirrored in .wslconfig (Windows 11 22H2 and later), WSL uses the Windows addresses. For the Windows side, see how to find your IP address on Windows.

How to change the IP address or set a static IP on Linux

A DHCP reservation in the router is often simpler than a fixed address on the device; static vs. dynamic IP addresses explains when each fits.

Warning

A wrong setting on a remote server ends your SSH session. Keep console access, or use sudo netplan try, which rolls back automatically.

Temporary: ip addr add

These changes are lost after a reboot or when NetworkManager reconnects:

Shell
sudo ip addr add 192.168.1.50/24 dev enp3s0   # add a second address
sudo ip addr del 192.168.1.50/24 dev enp3s0   # remove it again

Permanent with NetworkManager (desktops, Fedora, RHEL)

Shell
nmcli connection show    # find the connection name, e.g. "Wired connection 1" or "netplan-enp3s0"
sudo nmcli connection modify "Wired connection 1" \
  ipv4.method manual \
  ipv4.addresses 192.168.1.50/24 \
  ipv4.gateway 192.168.1.1 \
  ipv4.dns "192.168.1.1"
sudo nmcli connection up "Wired connection 1"

To go back to DHCP, run sudo nmcli connection modify "Wired connection 1" ipv4.method auto ipv4.addresses "" ipv4.gateway "" ipv4.dns "", then the same up command. In GNOME Settings, use the gear icon’s IPv4 tab: set IPv4 Method to Manual, enter Address, Netmask and Gateway, then click Apply.

Permanent with Netplan (Ubuntu Server)

Ubuntu Server keeps its network setup in YAML files in /etc/netplan/. List them with ls /etc/netplan/ and edit the file for your interface. This example follows Ubuntu’s network configuration guide:

YAML
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [192.168.1.1, 1.1.1.1]
Shell
sudo chmod 600 /etc/netplan/*.yaml   # Netplan warns if the files are readable by others
sudo netplan try                      # press Enter within 120 seconds to keep the change
sudo netplan apply

On cloud VMs, cloud-init generates 50-cloud-init.yaml and may overwrite your edits; change the address in the provider’s console instead. Debian servers without NetworkManager use /etc/network/interfaces rather than Netplan.

When ip a shows no usable IP address

  • No inet line, or a 169.254.x.x address: the interface got no address from DHCP. Check the cable or Wi-Fi, run nmcli device status, then reconnect with sudo nmcli connection up "<name>". See what a 169.254 IP address means for more causes.
  • Only 127.0.0.1: you’re looking at lo or ran hostname -i. Use ip -br a.
  • A 172.17.x.x or 192.168.122.x address: that’s Docker or libvirt, not your LAN. ip route get 1.1.1.1 shows which address carries your traffic.

For phones, Macs, printers and other devices, see find your IP address on any device.

Frequently asked questions

What is the command to get the IP address on Ubuntu?

Run ip a (short for ip addr show) in a terminal and read the inet line under your Ethernet or Wi-Fi interface, for example inet 192.168.1.23/24. hostname -I prints all of the machine’s addresses on one line without the prefix length. Both show the local IP; to see the public IP from the terminal, run dig -4 +short myip.opendns.com @resolver1.opendns.com.

How do I find my IP address in Kali Linux?

Kali Linux is based on Debian, so the same commands work: open a terminal and run ip a, then read the inet line under eth0 or your Wi-Fi interface (wlan0 or a wl name). hostname -I prints the addresses on one line. In a virtual machine, the address you see is the VM’s address on the hypervisor’s virtual network, which depends on whether the VM uses NAT or bridged networking.

What is nslookup in Linux?

nslookup is a command that asks a DNS server for the IP address of a hostname, for example nslookup example.com, or for the hostname behind an IP address. It does not show your own IP address. On Debian and Ubuntu it comes in the bind9-dnsutils package (the dnsutils package installs it), and on Fedora in bind-utils, together with the more detailed dig command.

What is the Linux equivalent of ipconfig?

The closest equivalent is ip a, which lists every interface with its IPv4 and IPv6 addresses; ip route shows the default gateway. nmcli device show adds the DNS servers on systems that use NetworkManager, and resolvectl status shows them on systems with systemd-resolved. The older ifconfig command still exists in the net-tools package but is deprecated and often not installed.

Why does hostname -i show 127.0.1.1?

hostname -i does not read your network interfaces. It resolves the computer’s own hostname, and Debian and Ubuntu map the hostname to 127.0.1.1 in /etc/hosts, so that loopback address comes back. Use hostname -I (capital I) or ip a to see the addresses that are actually configured on your interfaces.

How do I find my public IP address on Linux?

Run dig -4 +short myip.opendns.com @resolver1.opendns.com, which asks a DNS server to return the address your request came from. On a home network, ip a does not show your public IPv4 address, because it sits on your router or the provider’s gateway. Exceptions are servers with a public IPv4 address on the interface and IPv6 addresses marked scope global, which are usually public.

Look up IP addresses in your code

iplookupapi returns the location, provider, time zone and security flags of any IP address as JSON. The free plan includes 150 requests a month.

curl "https://api.iplookupapi.com/v1/info?ip=8.8.8.8" \
  -H "apikey: YOUR_API_KEY"