Skip to main content

3 Ways to Find IP Addresses in Linux

·824 words·4 mins
Linux Networking IP Address Ifconfig Ip Command Hostname Network Troubleshooting
Table of Contents

3 Ways to Find IP Addresses in Linux

Finding IP addresses is a routine task in Linux administration, network troubleshooting, server configuration, and security diagnostics. Depending on the environment, you may need the addresses assigned to all network interfaces, the address of a specific interface, or the host’s currently configured addresses.

Linux provides several command-line tools for retrieving this information. This guide covers three commonly used approaches: ifconfig, ip, and hostname.

Note: The ip command is the modern, preferred tool on most Linux distributions. ifconfig is considered legacy and may not be installed by default on newer systems.

๐ŸŒ Method 1: Use the ifconfig Command
#

ifconfig is a traditional Linux networking utility for displaying and configuring network interfaces. It can show interface status, IPv4 and IPv6 addresses, netmasks, broadcast addresses, MAC addresses, and packet statistics.

To display information for all available network interfaces, run:

ifconfig

Look for the inet field under the relevant interface. For example:

eth0: flags=4163  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe3f:bcde  prefixlen 64  scopeid 0x20
        ether 08:00:27:3f:bc:de  txqueuelen 1000  (Ethernet)
        RX packets 1001011  bytes 717493201 (683.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 543209  bytes 103511267 (98.7 MiB)
        TX errors 0  dropped 0  overruns 0  carrier 0  collisions 0

Here, 192.168.1.100 is the IPv4 address assigned to eth0.

Query a specific network interface
#

To inspect only eth0, use:

ifconfig eth0

This is useful when a system has multiple interfaces and you want to inspect one interface without filtering the output manually.

Because ifconfig belongs to the older net-tools package, it may need to be installed separately on modern distributions. For new scripts and administration workflows, prefer the ip utility.

๐Ÿ”ง Method 2: Use the ip Command
#

The ip command is part of the modern Linux networking toolset and provides a comprehensive interface for inspecting and managing addresses, interfaces, routes, and other networking state.

To display addresses for all interfaces, run:

ip addr show

A typical interface entry may look like this:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
    inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever

The inet 192.168.1.100/24 field indicates the IPv4 address and CIDR prefix length.

Query a specific interface
#

To inspect only eth0, run:

ip addr show eth0

You can also use the shorter form:

ip a

For IPv4 addresses specifically, this command is convenient:

ip -4 addr show

Likewise, to display only IPv6 addresses:

ip -6 addr show

For many Linux administration tasks, ip is the best default because it is widely available, scriptable, and supports much more than simply displaying IP addresses.

๐Ÿ–ฅ๏ธ Method 3: Use the hostname -I Command
#

If you simply need the IP addresses currently assigned to the host, hostname -I provides a concise alternative:

hostname -I

For example:

192.168.1.100

If the host has multiple addresses, the command may return several space-separated values:

192.168.1.100 10.0.0.25

This approach is particularly useful when you do not need detailed interface metadata and only want the addresses associated with the local machine.

Keep in mind that hostname -I is less informative than ip addr show. It does not provide the interface name, prefix length, link state, routing information, or other network configuration details.

๐Ÿ“Š Which Linux IP Address Command Should You Use?
#

The three commands serve slightly different purposes:

Method Primary Strength Best Use Case
ifconfig Legacy interface inspection Maintaining older systems or familiar legacy workflows
ip addr Detailed, modern network information Network administration, troubleshooting, and automation
hostname -I Concise host IP output Quickly retrieving local IP addresses

For modern Linux systems, ip addr should generally be your first choice. It provides substantially more networking information and is the standard replacement for many ifconfig workflows.

Use hostname -I when you only need the host’s configured IP addresses and want minimal output.

Use ifconfig primarily when working with legacy environments or existing operational procedures that still depend on net-tools.

๐Ÿงช Practical Examples for Network Troubleshooting
#

When troubleshooting a Linux network configuration, combining these commands can provide a quick overview.

First, inspect all interfaces and addresses:

ip addr show

Then inspect the routing table:

ip route

If you only need the host’s assigned addresses:

hostname -I

On an older system where ifconfig is available, you can also inspect the interface directly:

ifconfig eth0

This combination helps distinguish between problems involving interface configuration, IP assignment, and routing.

โœ… Summary
#

Linux provides several command-line tools for discovering IP addresses, but they are not equally suited to modern systems.

The most useful commands are:

# Modern and detailed
ip addr show

# Concise host addresses
hostname -I

# Legacy interface information
ifconfig

For everyday Linux administration, ip addr show is the recommended general-purpose option. It exposes interface addresses and network state while also providing a foundation for more advanced network management.

Understanding these commands makes it easier to diagnose connectivity issues, verify interface configuration, configure services, and troubleshoot Linux networking from the command line.

Related

BlueZ on Embedded Linux: A Practical Guide to Bluetooth Classic and BLE
·1318 words·7 mins
Embedded Linux BlueZ Bluetooth BLE Yocto Linux GATT RFCOMM C Programming
Embedded Linux init Explained: BusyBox, SysVinit, and systemd
·1349 words·7 mins
Embedded Linux Linux Init BusyBox SysVinit Systemd Buildroot Yocto Linux Boot Process Embedded Systems
How to Set Up a DNS Server on Linux with BIND
·781 words·4 mins
Linux DNS BIND System Administration Networking