How to View IP Address in Linux
If you're using Linux and need to see your IP address, this guide walks you through the simplest commands and methods to view both IPv4 and IPv6 addresses on your system. Whether you're troubleshooting network connections, configuring services, or just curious about your network identity, the techniques described here will help you quickly discover the addresses assigned to your network interfaces Less friction, more output..
Introduction
Linux provides several built‑in tools that let you inspect network configuration without installing extra software. Practically speaking, while ifconfig is still widely available, the modern ip command is recommended because it is faster, more flexible, and part of the core networking utilities. Practically speaking, the most common commands are ifconfig, ip, hostname -I, and nmcli (for systems that use NetworkManager). This article will cover both legacy and contemporary approaches, explain what the output means, and answer frequently asked questions to ensure you can confidently read and interpret IP address information on any Linux distribution.
How to View IP Addresses Using the ip Command
The ip utility is the de‑facto standard for low‑level network manipulation in Linux. It can display addresses, routes, links, and more. Follow these steps to list your IP addresses:
- Open a terminal emulator (Ctrl + Alt + T or equivalent).
- Run
ip -4 addr showto display only IPv4 addresses.- Example output:
2: eth0 inet 192.168.1.45/24 brd 192.168.1.255 scope global dynamic eth0 - The
inetline shows the IPv4 address (192.168.1.45) and its netmask (/24).
- Example output:
- Run
ip -6 addr showto display only IPv6 addresses.- Example output:
2: eth0 inet6 2001:0db8:85a3:0000:0000:8a2e:0370:7334/64 scope global dynamic - The
inet6line shows the IPv6 address and prefix length.
- Example output:
- For a combined view of both families, use
ip addr show(or simplyip a). This merges IPv4 and IPv6 information in a concise format.
Tip: If you need a quick, one‑line summary of all active addresses, try ip -brief addr show. It prints each interface name, its state, and the assigned IP(s) in a compact layout.
Using ifconfig (Legacy Method)
Many older distributions still include ifconfig. Though it is considered deprecated, it remains useful for learning and on systems where the ip command is not installed. To view IP addresses:
- Launch a terminal.
- Run
ifconfig(orifconfig -afor all interfaces, including down ones). - Locate the
inetline for IPv4 andinet6line for IPv6.- Example:
eth0 Link encap:Ethernet HWaddr 00:15:17:XX:XX:XX inet addr:192.168.1.45 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr:2001:db8:85a3::8a2e:370:7334/64 Scope:Global
- Example:
Note: Some modern distributions remove ifconfig entirely. If the command is missing, you can install it via apt install net-tools (Debian/Ubuntu) or yum install net-tools (RHEL/CentOS).
Checking IPs with hostname -I
When you only need the primary IPv4 address of the system (usually the one used for external communication), the hostname command offers a shortcut:
- Run
hostname -I. - It returns a space‑separated list of all active IPv4 addresses, e.g.,
192.168.1.45 10.0.0.5.
This method is handy for scripts that need a single IP without parsing the full interface details.
NetworkManager’s nmcli Command
If your desktop environment uses NetworkManager, you can query IP information through its command‑line tool nmcli:
- Open a terminal.
- Execute
nmcli device show <interface>(replace<interface>witheth0,wlan0, etc.). - Look for the
IP4.ADDRESSandIP6.ADDRESSfields.
Example output snippet:
GENERAL.DEVICE: eth0
IP4.That's why aDDRESS[1]: 192. On the flip side, 168. 1.45/24
IP6.
`nmcli` is especially useful when you need to extract data programmatically, as it returns key‑value pairs that can be parsed easily.
## Understanding the Output
When you view IP addresses, the displayed information includes more than just the numeric address. Understanding each component helps you diagnose network problems:
- **inet / inet6**: The assigned IP address.
- **/24 or /64**: The *prefix length* (netmask for IPv4, prefix for IPv6). It defines the network portion of the address.
- **brd** (broadcast) for IPv4 indicates the broadcast address of the subnet.
- **scope** describes the address scope (global, link‑local, host, etc.).
- **dynamic** suggests the address was assigned via DHCP.
For IPv6, you may also see *preferred* and *deprecated* states, indicating whether the address is currently usable or slated for removal.
## Common Scenarios and Quick Commands
| Scenario | Command | What You’ll See |
|----------|---------|-----------------|
| List all interfaces with IPs | `ip -brief addr show` | Interface name, state, and IP(s) |
| Find the default gateway | `ip route show default` | The gateway IP (e.Practically speaking, 1. And , `via 192. g.168.1`) |
| Detect *link‑local* IPv6 (LLA) | `ip -6 addr show scope link` | Addresses starting with `fe80::` |
| Check DNS resolution for a domain | `dig example.
These shortcuts can be combined to build a comprehensive network picture without opening graphical tools.
## Scientific Explanation: How Linux Determines IP Addresses
Linux obtains IP addresses through several mechanisms, each leaving a trace in the system:
1. **Static Configuration** – Defined in `/etc/network/interfaces` (Debian/Ubuntu) or `/etc/sysconfig/network-scripts/ifcfg-` (RHEL). These files contain `BOOTPROTO=static` and `IPADDR=`.
2. **DHCP** – When `BOOTPROTO=dhcp` (or via NetworkManager’s “Automatic” setting), the `dhclient` or `systemd‑dhcp-client` process requests an address from the local DHCP server and updates the interface’s `inet` entry.
3. **IPv6 Autoconfiguration** – Stateless Address Autoconfiguration
(SLAAC) allows IPv6 addresses to be generated automatically based on router advertisements. The kernel listens for **Router Advertisement (RA)** messages containing network prefixes, then combines them with the interface’s MAC address (or a privacy extension) to form a complete IPv6 address.
4. **Link‑Local Addresses** – Automatically assigned to every interface, these are essential for local communication and services like mDNS/zeroconf.
---
## Advanced Tips for Network Diagnostics
### Filtering Output with `grep` or `awk`
For scripting or automation, parsing raw output is often necessary:
```bash
ip -4 addr show eth0 | grep inet | awk '{print $2}'
This extracts only the IPv4 address from eth0 That's the part that actually makes a difference..
Using hostname Commands
To quickly retrieve your machine’s primary IP:
hostname -I
Note: This shows all IPs and may not reflect the default route’s interface Practical, not theoretical..
Checking Routes and Gateways
Use this command to verify routing:
ip route
Look for lines starting with default, which indicate the default gateway used for outbound traffic That's the whole idea..
Viewing DNS Configuration
Check resolved nameservers:
cat /etc/resolv.conf
Modern systems might use systemd-resolved, so also try:
resolvectl status
Troubleshooting Checklist
-
No IP Address?
- Is the interface enabled?
ip link setup - Was DHCP attempted?
dhclient
- Is the interface enabled?
-
Wrong Subnet?
- Confirm netmask/prefix matches expected values.
- Recheck static config files if applicable.
-
IPv6 Not Working?
- Ensure SLAAC or DHCPv6 is supported by your router.
- Disable privacy extensions temporarily to test stability.
-
DNS Issues?
- Ping an IP directly first (e.g.,
ping 8.8.8.8) to isolate DNS vs connectivity issues. - Try changing DNS servers manually in
/etc/resolv.conf.
- Ping an IP directly first (e.g.,
Conclusion
Understanding how to view and interpret IP addresses on Linux empowers users to manage networks effectively—from basic checks using ip addr to advanced diagnostics involving routing tables and DNS resolution. Whether working with IPv4 or IPv6, manual configuration or dynamic assignment, mastering these tools ensures smooth operation across diverse environments. With practice, even complex scenarios become manageable through simple yet powerful terminal commands.