Finding your IP address on Linux is a fundamental skill for system administrators, developers, and everyday users troubleshooting network connectivity. Whether you are configuring a firewall, setting up a static IP, or simply trying to SSH into a remote server, knowing how to locate both your private (local) and public (external) addresses is essential. This guide covers every standard method, from modern command-line tools to legacy utilities and graphical interfaces, ensuring you can retrieve this information regardless of your distribution or desktop environment.
Understanding Private vs. Public IP Addresses
Before diving into the commands, it is important to distinguish between the two types of addresses you will encounter.
A private IP address (often called a local IP) is assigned by your router via DHCP or configured statically. Practically speaking, it is used for communication inside your local area network (LAN). That's why these addresses typically fall within reserved ranges: 10. On the flip side, 0. Think about it: 0. 0/8, 172.16.In practice, 0. In real terms, 0/12, or 192. 168.0.0/16. This is the address you use to talk to your printer, NAS, or other computers on the same Wi-Fi.
A public IP address is assigned by your Internet Service Provider (ISP). Day to day, it is the address the outside world sees when you visit a website or host a server. Because Linux machines usually sit behind a router performing Network Address Translation (NAT), the operating system itself is often unaware of its public IP. You must query an external service to discover it Surprisingly effective..
Method 1: Using the ip Command (Modern Standard)
The ip command is part of the iproute2 package and is the modern replacement for the deprecated ifconfig. It is available on virtually all contemporary distributions, including Ubuntu, Debian, Fedora, Arch, and RHEL.
To display all network interfaces and their associated IPv4 and IPv6 addresses, open a terminal and type:
ip addr show
You can shorten this to ip a or ip addr. The output lists every interface (like lo for loopback, eth0 or enp3s0 for Ethernet, and wlan0 or wlp2s0 for Wi-Fi). Look for the inet field under your active interface for the IPv4 address and inet6 for IPv6 Still holds up..
Example output snippet:
2: enp3s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.15/24 brd 192.168.1.255 scope global dynamic noprefixroute enp3s0
valid_lft 86399sec preferred_lft 86399sec
inet6 fe80::1234:5678:9abc:def0/64 scope link noprefixroute
valid_lft forever preferred_lft forever
In this example, 192.Now, 15 is the private IPv4 address. This leads to 255. Because of that, 1. 168.255.That's why the /24 represents the subnet mask (255. 0).
Filtering for Cleaner Output
If you only want the IP address without the extra metadata (useful for scripting), combine ip with grep and awk:
ip -4 addr show scope global | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
The -4 flag limits output to IPv4, and scope global excludes the loopback interface (127.0.Even so, 0. 1) Less friction, more output..
Method 2: Using hostname for Quick Retrieval
The hostname command offers a remarkably simple way to grab the primary IP address assigned to the hostname Simple, but easy to overlook. Which is the point..
hostname -I
Note the capital -I (not lowercase -i, which returns the loopback address 127.0.Day to day, 0. 1 or the hostname resolution). On the flip side, this command prints all configured network addresses for the host, separated by spaces. It is the fastest way to get a clean list of private IPs if you have multiple interfaces (e.g., Docker bridges, VPN tunnels, Ethernet, and Wi-Fi active simultaneously).
Method 3: Legacy ifconfig (Deprecated but Still Common)
Despite being deprecated in favor of ip, ifconfig (interface configuration) remains installed by default on many systems or is easily installable via the net-tools package.
ifconfig
Or for a specific interface:
ifconfig eth0
Look for inet addr: (older versions) or inet (newer builds) under your active network interface. If the command is not found, install it using your package manager:
- Debian/Ubuntu:
sudo apt install net-tools - RHEL/Fedora/CentOS:
sudo dnf install net-tools - Arch:
sudo pacman -S net-tools
Method 4: Using nmcli (NetworkManager CLI)
On desktop-focused distributions (Fedora, Ubuntu Desktop, RHEL, CentOS), NetworkManager is the standard service managing network connections. Its command-line tool, nmcli, provides detailed, human-readable output And that's really what it comes down to..
To see a summary of all devices and their IPs:
nmcli device show
To see only the IP4 address for a specific connection (replace Wired connection 1 with your connection name):
nmcli -g IP4.ADDRESS connection show "Wired connection 1"
This is particularly useful on headless servers managed via Cockpit or Ansible where NetworkManager is the backend Simple, but easy to overlook..
Method 5: Finding Your Public IP Address
Since your Linux machine does not know its public IP directly (it sits behind a router), you must ask an external server "What IP do you see me coming from?" The most reliable way is using curl or wget against a dedicated API endpoint.
Using curl (Recommended)
curl ifconfig.me
Other reliable endpoints include:
curl icanhazip.ipify.comcurl ipinfo.io/ipcurl api.That's why org- `curl checkip. amazonaws.
These services return only the IP address as plain text, making them perfect for scripts.
Using wget
If curl is not installed:
wget -qO- ifconfig.me
Using dig (DNS Query Method)
You can also query OpenDNS resolvers to return your public IP. This is often faster and more reliable than HTTP APIs because it uses UDP DNS traffic.
dig +short myip.opendns.com @resolver1.opendns.com
Method 6: Graphical User Interface (GUI) Methods
If you prefer not to use the terminal, every major Desktop Environment (DE) provides a network settings panel.
GNOME (Ubuntu, Fedora, Debian Default)
- Open Settings.
- work through to Network (or Wi-Fi).
- Click the Gear icon next to your active connection.
- A dialog appears showing IPv4 Address, IPv6 Address, Default Route, and DNS.
KDE Plasma (Kubuntu, Fedora KDE, openSUSE)
- Open System Settings.
- Go to Connections (or Network).