How to Check Your IP Address on Linux

Knowing your IP address on Linux is one of those fundamental networking tasks that comes up constantly — whether you're configuring a server, troubleshooting a connection, setting up SSH, or just getting oriented on a new machine. The good news: Linux gives you multiple ways to find it, and understanding which method fits your situation makes the process significantly faster.

What "IP Address" Actually Means in This Context

Before running any commands, it's worth clarifying what you're looking for, because Linux machines often have more than one IP address.

  • Loopback address (127.0.0.1) — This is a self-referencing address every Linux system has. It's used internally and not useful for network identification.
  • Private (local) IP address — The address your machine has on your local network (home, office, or data center LAN). Typically starts with 192.168.x.x, 10.x.x.x, or 172.16–31.x.x.
  • Public IP address — The address the outside internet sees. This is assigned by your ISP or cloud provider, and it sits at the router or gateway level — not directly on your machine in most home setups.

Most day-to-day tasks (SSH, local file sharing, internal server config) need your private IP. Publicly accessible services need your public IP.

Checking Your Private IP Address 🖥️

The Modern Method: ip addr

The most current and widely supported command is:

ip addr show 

Or the shorthand:

ip a 

This outputs all network interfaces and their assigned addresses. Look for entries like inet 192.168.1.45/24 — the number before the slash is your IPv4 address. You'll also see IPv6 addresses listed under inet6.

To narrow it down to a specific interface (like eth0 for wired or wlan0 for Wi-Fi):

ip addr show eth0 

The Older Method: ifconfig

On older distributions or systems where net-tools is installed, ifconfig still works:

ifconfig 

Look for the inet field under your active interface. On some distros, you may need to install it first:

sudo apt install net-tools 

ifconfig has been deprecated in favor of ip on most modern distributions, but it still functions reliably where available.

Filtering Output with grep

If you want a cleaner result without parsing walls of text:

ip addr show | grep "inet " 

This filters to show only IPv4 address lines across all interfaces.

Checking Your Public IP Address 🌐

Your public IP isn't stored locally in the same way — you need to query an external service. From the terminal:

curl ifconfig.me 

Or alternatives that do the same thing:

curl icanhazip.com curl api.ipify.org 

These services return your public-facing IP as seen from the internet. This requires an active internet connection. If you're on a machine behind NAT (like most home networks and many cloud VPCs), the public IP won't match anything shown by ip addr.

Checking the Default Gateway and Routing

Sometimes the goal isn't just your IP — you need to understand how your machine sits within the network. The routing table shows your default gateway (your router's IP) and which interface handles outbound traffic:

ip route show 

The line starting with default via shows the gateway address. This is useful when diagnosing why traffic isn't reaching the internet or why a specific interface isn't being used.

Quick Reference: Common Commands

TaskCommand
Show all IPs (modern)ip addr show or ip a
Show all IPs (legacy)ifconfig
Show specific interfaceip addr show eth0
Filter IPv4 addresses onlyip addr show | grep "inet "
Check public IPcurl ifconfig.me
Show routing tableip route show
Show default gatewayip route | grep default

Variables That Affect Which Method Works Best

Not every approach works equally well across all setups. A few factors shape which commands are available and what output you'll see:

Distribution and version — Modern distros (Ubuntu 20.04+, Fedora, Debian 10+, RHEL 8+) ship with iproute2 tools (ip command) by default. Older systems may only have net-tools (ifconfig). Some minimal server images strip out both and require installation.

Number of interfaces — Servers often have multiple NICs, virtual interfaces (like Docker's docker0 or VPN tunnels like tun0), and loopback. The output from ip addr can be verbose on these machines, making interface-specific commands more practical.

Cloud and virtualized environments — On AWS, GCP, Azure, or similar platforms, IP addressing works differently. Instances often have private IPs assigned by the cloud provider, and the "public IP" is handled via elastic IPs or NAT at the infrastructure level — meaning curl ifconfig.me and ip addr will return different addresses, and both are correct in different contexts.

Containers and WSL — If you're running Linux inside Docker or Windows Subsystem for Linux, the IP you see may be the container or virtual machine's address, not the host machine's. This distinction matters depending on what you're trying to accomplish.

Privileges — Most IP checking commands work without sudo. Some interface management tasks (bringing interfaces up/down, setting IPs) require elevated permissions, but reading your current IP does not.

Understanding What You're Actually Seeing

The same physical machine can legitimately show different IPs depending on which interface you check, whether you're looking at private vs. public, whether VPNs are active, and whether the machine has multiple network connections active simultaneously. A laptop on Wi-Fi, connected to a VPN, and running a Docker container could show four or more different IP addresses — all valid, all for different purposes.

That layered reality is why the "right" IP to use depends entirely on what you're trying to do with it — and which piece of your network or application stack needs to reach the machine.