On Linux you will usually be in a terminal, sometimes on a server with no screen at all, and "what is my IP?" has two different answers: the local IP your machine has on its network, and the public IP the internet sees. This guide gives you the commands for both on Ubuntu, Debian, Fedora, Arch and friends, explains how to read the output, and covers what to do when the address is missing, wrong or keeps changing.
Find your public IP
If you have a desktop, open the Show-IP.ir homepage in a browser. On a headless server or over SSH, the same site answers a plain command-line request with just your address:
curl show-ip.ir
curl show-ip.ir/ip
wget -qO- show-ip.ir
Run on a server, this returns the server's public address, which is usually what you want to know. If you are connected to a VPN, a proxy or a tunnel, it returns the address of that exit point instead, which makes it a handy VPN check (see how to test a VPN for leaks).
Find your local IP
The modern tool is ip from the iproute2 package, installed on practically every distribution:
ip addr show # every interface with all of its addresses
ip -4 -brief addr # compact, IPv4 only, one line per interface
ip -4 addr show wlan0 # only one interface
hostname -I # just the addresses, space-separated
In the long output, the line that starts with inet holds the IPv4 address with its prefix length, for example inet 192.168.1.23/24. The /24 is the subnet mask in CIDR notation. Lines starting with inet6 are IPv6 addresses.
On desktops managed by NetworkManager you can also run nmcli device show and read the IP4.ADDRESS, IP4.GATEWAY and IP4.DNS lines in one place.
The old way: ifconfig
ifconfig comes from the older net-tools package. It still works if installed, and many tutorials use it, but newer systems no longer ship it by default. If you see "command not found", use ip addr instead — or install the package (sudo apt install net-tools on Debian/Ubuntu).
| Task | Modern command | Old command |
|---|---|---|
| Show addresses | ip addr | ifconfig |
| Show the routing table / gateway | ip route | route -n |
| Show neighbours (ARP) | ip neigh | arp -a |
| Show open sockets | ss -tulpn | netstat -tulpn |
Reading interface names
lo— the loopback interface, always127.0.0.1. It is not your network address.eth0,enp3s0,eno1— wired Ethernet. Modern systemd names encode the hardware location.wlan0,wlp2s0— Wi-Fi.docker0,br-...,virbr0— virtual bridges created by Docker or virtualization; their addresses are not your LAN address.tun0,wg0— VPN tunnels (OpenVPN, WireGuard).
Pick the interface that is UP and has the default route. Your gateway — usually the router — is shown by ip route | grep default; the address after via is what you type to open the router page (router login guide).
Troubleshooting
The interface has no IPv4 address
Check that the link is up (ip link), then ask for a new lease. With NetworkManager: nmcli connection down "NAME" && nmcli connection up "NAME" (get the name from nmcli connection show). On a server with systemd-networkd: networkctl renew eth0. On very old setups: sudo dhclient -r && sudo dhclient.
The address starts with 169.254
That is a link-local fallback: the machine asked for an address and no DHCP server answered. Check the cable or Wi-Fi password, restart the router, and make sure its DHCP server is enabled. Until then the machine can talk only to neighbours on the same segment, with no internet.
The IP keeps changing
A DHCP lease may change after a reboot or when it expires. For a server, set a static address in NetworkManager (nmcli), netplan or /etc/network/interfaces, or — simpler and safer — give the machine a DHCP reservation in the router, so it always gets the same address. The reservation works by MAC address; see IP vs MAC address. If your public IP changes, that comes from your ISP: static vs dynamic IP.
Local and public IP disagree and I cannot connect from outside
Your server sits behind NAT or even CGNAT. Forwarding a port on the router (port forwarding) works only when your connection has a true public address; compare the two as explained in the CGNAT article.
Frequently asked
Why does hostname -I print several addresses?
One per interface address: Wi-Fi, Ethernet, Docker bridges, VPN tunnels and IPv6 all appear. Use ip -4 -brief addr to see which interface each belongs to.
Which command works on every distribution?
ip addr on anything modern and hostname -I on most; ifconfig only where net-tools is installed.
Key takeaways
- Public IP:
curl show-ip.ir(or the homepage in a browser). Local IP:ip addr show,ip -4 -brief addrorhostname -I. ifconfigis legacy;ipreplaces it.- Ignore
lo(127.0.0.1) and virtual bridges when you want your LAN address. - 169.254.x.x means DHCP failed; a DHCP reservation in the router is the cleanest way to keep a stable local IP.