Skip to Content

3 Linux commands to list network interfaces

Introduction

Linux stands as a bastion of network management, offering a suite of powerful tools and commands for effective network administration. Among these, understanding and managing network interfaces is a crucial skill for any Linux system administrator.

Network interfaces in Linux are the points through which devices communicate with external networks. This article delves into three essential commands for discovering and managing these interfaces: ifconfig, ip, and NetworkManager tools.

We’ll explore their functionalities, differences, and how they interplay with other Linux network concepts and configurations.

Understanding Network Interfaces in Linux

In the Linux ecosystem, network interfaces are points of communication between the system and the external networks. These interfaces can be either hardware (like Ethernet cards, designated as eth0) or virtual.

Each network interface in Linux is associated with unique identifiers, such as the MAC (Media Access Control) address, which provides a distinct hardware identity.

Understanding the difference between IPv4 and IPv6, the internet protocols that assign addresses to these interfaces, is also critical. IPv4 uses 32-bit addresses, while IPv6 uses 128-bit, allowing for a larger address space.

Read More:

8 Powerful Linux Tools to Solve Your Network Woes

Command 1: ifconfig

Traditionally, ifconfig (interface configuration) was the go-to tool for managing network interfaces in Linux.

It is used to configure, control, and query TCP/IP network interface parameters. Through ifconfig, you can activate or deactivate interfaces, assign IP addresses, set up netmasks, and view network configuration.

Usage:

ifconfig
ifconfig [interface]

For example, ifconfig eth0 displays current information about the eth0 Ethernet interface, including the IP address, netmask, and the status (up/down).

However, ifconfig is being phased out in favor of the more robust ip command and is absent by default in some modern Linux distributions. Despite this, understanding its basics remains valuable for managing older systems or those that still employ it.

Command 2: ip

The ip command is part of the iproute2 package in Linux and is the modern replacement for ifconfig. It offers more comprehensive features for network interface management and is designed to work seamlessly with advanced networking concepts like VLANs and IP routing.

Basic usage for displaying all interfaces is:

ip addr show

This command lists all network interfaces, their IP addresses, and additional information like the global scope of IPv6 addresses. The ip command is versatile, allowing users to add or delete IP addresses, set route tables, and much more.

Command 3: NetworkManager and nmcli

NetworkManager simplifies network configuration and automation in Linux. It’s particularly user-friendly for managing wireless networks and VPN configurations. The nmcli (Network Manager Command Line Interface) tool allows control of NetworkManager and is especially useful for scripting and automation.

Using nmcli, you can quickly connect to different networks, display network interface status, and configure network settings like SSID (the name of a Wi-Fi network) and DHCP (Dynamic Host Configuration Protocol), which automates IP address allocation on networks.

Displaying All Network Interfaces

nmcli device status

This command lists all network devices and their status.

Enabling and Disabling a Network Interface

nmcli device disconnect [interface]

nmcli device connect [interface]

Enable or disable a network interface.

Setting a Static IP Address for an Ethernet Interface

nmcli con mod [connection-name] ipv4.addresses [IP_address]/24 ipv4.gateway [gateway_address] ipv4.dns "[DNS_addresses]" ipv4.method manual

Configure a static IP with the specified connection details.

Additional Concepts and Tools

Understanding network interfaces in Linux also involves familiarity with several other concepts and tools:

  • ss: A utility that provides detailed information about network sockets, replacing the older netstat command.
  • host: A simple utility for performing DNS lookups, useful for diagnosing DNS-related issues.
  • dig: Another DNS lookup tool, offering detailed query information, commonly used for troubleshooting and analyzing DNS problems.
  • /etc/network/interfaces: This file is fundamental in some distributions for setting up network interfaces.
  • systemd-networkd: Part of the systemd suite, this tool is used for advanced network configuration in newer Linux systems.
  • route: This command allows viewing and manipulation of the IP routing table, which is crucial for directing network traffic.
  • iptables/nftables: These are tools for configuring network packet filtering rules, essential for network security and management.
  • /etc/resolv.conf: This file is used for DNS configuration, specifying how domain names are resolved to IP addresses.

Conclusion

Navigating the Linux network interface landscape requires familiarity with various commands and concepts. From the legacy ifconfig to the modern ip and the dynamic NetworkManager, these tools form the backbone of network interface management in Linux.

Understanding these utilities, along with concepts like MAC addresses, IPv4/IPv6, and DHCP, equips you with the knowledge to manage complex network setups effectively. Whether you’re a budding system administrator or a seasoned professional, mastering these aspects of Linux is key to ensuring robust and efficient network management.