Knowing how to find the IP address of a Linux server is a fundamental skill for system administrators, developers, and anyone managing infrastructure. Whether you are troubleshooting a network issue, setting up a new service, or securing access, the IP address is the primary identifier for communication. This guide provides a clear, step-by-step approach to discovering both the public and private IP addresses on any Linux system.
Understanding IP Address Types
Before diving into the commands, it is essential to understand the two types of IP addresses you will encounter. A private IP address is used within your local network, such as a home or office environment, and is not routable on the public internet. Examples include addresses in the ranges 192.168.x.x or 10.x.x.x. Conversely, a public IP address is the global identifier assigned by your Internet Service Provider (ISP) that allows your server to be accessed from anywhere on the internet. The method to locate these differs slightly, and knowing which one you need is the first step.
Using the Command Line Interface
The most direct way to find the IP address of a Linux server is through the terminal. Modern distributions often include the ip command, which is part of the iproute2 package and is considered the successor to the older ifconfig utility. To view all network interfaces and their associated IP addresses, you can use the following command:
ip addr show This command outputs a significant amount of information. Look for the line labeled "inet" under the active interface, typically named eth0 , ens33 , or enp0s3 . The number listed next to "inet" is your private IP address. For a more concise output focusing only on the IP, you can use:
ip -4 addr show eth0 | grep -oP '(? Utilizing Hostname and Network Tools If the ip command is unavailable, older systems or minimal installations might rely on tools like hostname or ifconfig . The hostname command, when used with the -I flag, returns all IP addresses associated with the host:
Utilizing Hostname and Network Tools
hostname -I This is one of the simplest methods as it returns only the addresses without extra metadata. Alternatively, if the net-tools package is installed, you can use:
ifconfig Similar to the ip command, look for the "inet" field. Note that some systems might require you to install the net-tools package explicitly, as it is deprecated in favor of the iproute2 suite.
Finding the Public IP Address
To find the public IP address of your Linux server, you must query an external service, as the server has no inherent knowledge of the IP address assigned by your ISP. This is common when setting up VPNs or configuring firewall rules. You can use command-line tools like curl or wget to communicate with a dedicated IP echo service:
curl ifconfig.me curl icanhazip.com curl ident.me These commands send a request to the specified website, which responds with the IP address from which the request originated. This is the IP address that the internet sees, which is crucial for remote access and security configurations.