News & Updates

How to Find IP Address on Linux Server: Quick Command Line Guide

By Ava Sinclair 47 Views
how to find ip address onlinux server
How to Find IP Address on Linux Server: Quick Command Line Guide

Locating the IP address on a Linux server is a fundamental skill for system administrators and developers. Whether you are troubleshooting a network issue, configuring a firewall, or setting up a new service, knowing the exact IP configuration is critical for connectivity and security.

Understanding Network Interfaces

Before you can find an IP address, it is essential to understand the network interfaces available on your server. Linux systems can have multiple interfaces, such as eth0 for physical Ethernet or wlan0 for wireless, along with virtual interfaces like docker0 or lo (loopback). The loopback address, 127.0.0.1 , is used for internal communication within the server and is not reachable from external networks.

Using the ip Command

The modern and recommended way to find IP addresses is by using the ip command, which is part of the iproute2 package. This tool provides a clean and detailed output for network information. To view the IP address for all active interfaces, you can use the following command:

ip addr show

This command lists all interfaces along with their IPv4 and IPv6 addresses, subnet masks, and state. Look for the inet field under the specific interface you are interested in, such as eth0 or ens33 .

Leveraging the hostname Command

A quicker method to retrieve the primary IP address is to use the hostname utility. By adding the -I flag, the command displays all IP addresses assigned to the host.

hostname -I

This command is particularly useful in scripts or when you need a fast, human-readable list of addresses without the extra details provided by other tools.

Alternative Methods and Legacy Tools

Although the ip command is the standard in modern distributions, some older systems or specific environments might still rely on the ifconfig command. If ifconfig is not installed, you can install it via your package manager, though it is largely considered deprecated.

Using ifconfig

If available, running ifconfig will display configuration information for all network interfaces. Similar to the ip command, look for the inet addr field to identify the IPv4 address. For users on Red Hat-based systems, the equivalent tool might be nmcli , which provides a terminal-based interface for managing network connections.

Finding the Public IP Address

Internal IP addresses (such as 192.168.x.x or 10.x.x.x ) are used within a local network, but to communicate with the internet, your server needs a public IP address. To determine this, you can query an external service directly from the command line.

curl ifconfig.me

curl ipinfo.io/ip

wget -qO- http://checkip.amazonaws.com

These commands fetch your server's public-facing IP by contacting a simple web service. This is useful for setting up port forwarding, SSH access, or DNS records.

Verifying IPv6 Configuration

A

Written by Ava Sinclair

Ava Sinclair is a Senior Editor covering culture, travel, and premium experiences. She focuses on clear reporting and practical takeaways.