Knowing how to show ip address in linux is essential for troubleshooting network issues, configuring services, or simply verifying connectivity. Even so, whether you are managing a server, setting up a desktop workstation, or learning the basics of Linux networking, being able to retrieve your machine’s IP address quickly saves time and reduces frustration. This guide walks you through the most reliable command‑line tools, graphical options, and practical tips for displaying IPv4 and IPv6 addresses on any modern Linux distribution Small thing, real impact..
Understanding IP Addresses in Linux
Before diving into the commands, it helps to know what an IP address represents in the Linux networking stack. Each network interface—such as eth0, wlan0, or enp3s0—can have one or more IP addresses assigned. These addresses fall into two families:
- IPv4 – the traditional 32‑bit address (e.g.,
192.168.1.10). - IPv6 – the newer 128‑bit address (e.g.,
fe80::1a2b:3c4d:5e6f:7a8b).
Linux stores interface information in the kernel and exposes it through various utilities. The most modern and preferred tool is the ip command from the iproute2 package, while older scripts may still rely on ifconfig. Desktop environments often provide network managers with graphical applets, but the command line remains the fastest and most universal method.
Basic Commands to Show IP Address
Several commands can display IP address information. Below is a quick reference table that you can keep handy:
| Command | Primary Use | Output Example |
|---|---|---|
ip addr show |
Detailed view of all interfaces | 2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 ... inet 192.Here's the thing — 168. 1.That's why 10/24 |
hostname -I |
Simple list of IPv4 addresses | 192. 168.1.10 10.In practice, 0. 0.5 |
ifconfig (if installed) |
Legacy interface configuration | eth0: flags=4163<UP,BROADCAST,RUNNING> inet 192.168.1.10 netmask 255.255.255.0 |
nmcli device show |
NetworkManager‑centric view | IP4.ADDRESS[1]: 192.168.Think about it: 1. 10/24 |
curl -s https://ifconfig.me |
External IP (what the world sees) | `203.Even so, 0. 113. |
Each of these tools serves a slightly different purpose, but the ip command is generally the most reliable because it works on minimal installations and provides both IPv4 and IPv6 details in a single invocation That's the part that actually makes a difference..
Using the ip Command to Show IP Address
The ip utility is part of the iproute2 suite, which is installed by default on virtually all modern distributions (Ubuntu, Debian, Fedora, Arch, etc.). To display all addresses assigned to every network interface, run:
ip addr show
Breaking Down the Output
When you execute the command, you will see sections similar to the following:
1: lo: 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
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:1a:2b:3c:4d:5e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic eth0
valid_lft 86234sec preferred_lft 86234sec
inet6 fe80::21a:2bff:fe3c:4d5e/64 scope link
valid_lft forever preferred_lft forever
lois the loopback interface, always present with address127.0.0.1(IPv4) and::1(IPv6).eth0(or similar names like enp3s0, wlan0) shows the physical or virtual network card.- The line beginning with
inetgives the IPv4 address and its CIDR netmask (/24). - The line beginning with
inet6provides the IPv6 address.
Filtering for a Specific Interface
If you only need the address of one interface, you can limit the output:
ip -4 addr show dev eth0 # IPv4 only
ip -6 addr show dev eth0 # IPv6 only
The -4 and -6 flags force IPv4 or IPv6 display, respectively. Adding dev <name> restricts the query to that device.
Extracting Just the IP
For scripting, you may want only the raw address without extra text. Combine ip with grep and awk:
ip -4 addr show dev eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'
This returns something like 192.Because of that, 1. 168.10.
ip -
… `-6 addr show dev eth0 | grep -oP '(?<=inet6\s)[0-9a-f:]+(/[0-9]+)?'`
This pattern isolates the IPv6 address (including an optional prefix length) and prints something like `fe80::21a:2bff:fe3c:4d5e/64`.
### Getting Structured Output with `ip -json`
Modern `iproute2` builds support JSON output, which is far easier to parse programmatically:
```bash
ip -json -4 addr show dev eth0
Sample JSON:
[
{
"ifname": "eth0",
"addr": "192.168.1.10",
"prefixlen": 24,
"flags": [],
"scope": "global",
"dynamic": true
}
]
You can then feed this to jq to pull out exactly what you need:
ip -json -4 addr show dev eth0 | jq -r '.[0].addr'
# → 192.168.1.10
For IPv6:
ip -json -6 addr show dev eth0 | jq -r '.[0].addr'
# → fe80::21a:2bff:fe3c:4d5e
Brief and One‑Line Formats
When you only need a quick glance, the -br (brief) and -o (one‑line) options are handy:
ip -br -4 addr show
# OUTPUT
# lo UNKNOWN 127.0.0.1/8
# eth0 UP 192.168.1.10/24
The -o flag collapses each interface’s information onto a single line, which simplifies awk processing:
ip -o -4 addr show | awk '$2=="eth0" {print $4}'
# → 192.168.1.10/24
Selecting the Primary Address
Many interfaces (especially those managed by DHCP or cloud‑init) can acquire multiple addresses. If you want the address that is marked primary (or the first one when none is flagged), add the primary selector:
ip -4 -o addr show dev eth0 primary | awk '{print $4}'
Verifying Interface State Before Querying
In scripts it’s often wise to confirm that the interface is actually up before extracting its address:
if ip -o link show dev eth0 | grep -q 'state UP'; then
ip -4 addr show dev eth0 | awk '/inet/ {print $2}'
else
echo "eth0 is down or absent"
fi
Handling Multiple IPv4/IPv6 Addresses
To list all addresses assigned to a device, drop the -o flag and iterate:
# IPv4
ip -4 addr show dev eth0 | awk '/inet/ {print $2}'
# IPv6
ip -6 addr show dev eth0 | awk '/inet6/ {print $2}'
External (Public) IP Retrieval
While ip shows only locally assigned addresses, you often need the address the world sees. A lightweight, dependency‑free way is:
curl -s https://ifconfig.me/ip
Or,