Checking your IP address on Linux is a fundamental task for system administration, network troubleshooting, and security verification. Whether you are configuring a new server, diagnosing connectivity issues, or verifying your network setup, knowing how to quickly retrieve this information is essential. The process is straightforward, thanks to a suite of powerful command-line tools built into the Linux ecosystem.
Understanding IP Addresses in Linux
Before diving into the commands, it helps to understand the two primary types of IP addresses you will encounter. An IPv4 address is a 32-bit number typically represented in dotted-decimal notation, such as 192.168.1.100. IPv6 addresses are 128-bit addresses represented in hexadecimal, designed to replace IPv4 due to the exhaustion of available addresses. When you check IP address on Linux, you are usually looking for either of these two formats associated with your network interfaces.
Using the ip Command
The ip command is the modern and recommended utility for network configuration. It replaces the older ifconfig tool and provides a more consistent output. To view all network interfaces and their associated IP addresses, you can use the addr or a shorthand.
Running ip addr show will list every interface, including loopback, Ethernet, and wireless. Look for the inet field for IPv4 addresses and the inet6 field for IPv6 addresses. For a more concise output that shows only the active interfaces and their IPs, you can use ip -4 addr for IPv4 specifically or ip -6 addr for IPv6.
Filtering Specific Interfaces
If you want to check the IP address of a specific interface, such as eth0 or wlan0 , you can specify the interface name directly. The command ip addr show eth0 will display detailed information only for the Ethernet interface. This is particularly useful on servers with multiple network connections where you need to isolate data for a specific port.
Utilizing the hostname Command
A simpler method to check IP address on Linux involves the hostname utility. This command is often used to manage the system's host name, but it includes flags that allow it to display network information. The -I (capital i) option prints all IP addresses associated with the host, excluding loopback addresses.
This method is excellent for quick verification because it provides a clean, space-separated list of addresses without the additional metadata provided by the ip command. It effectively answers the question, "What is my current IP?" in a single line of output.
Checking the Public IP Address
While the commands above reveal your local network IP, sometimes you need to know your public IP address as seen from the internet. This is the address assigned by your Internet Service Provider (ISP) and is used for external communication. You can query external web services directly from the terminal using tools like curl or wget .
Common commands include curl ifconfig.me , curl ipinfo.io/ip , or wget -qO- icanhazip.com . These commands fetch the IP data from a remote server and display it in your terminal. This is the standard way to check IP address for purposes like port forwarding, firewall configuration, or verifying your VPN connection.