How to check if a network interface is active in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check the status of network interfaces on a Linux system. Network interfaces are crucial for network connectivity, and understanding their status is essential for troubleshooting and configuration.

Through hands-on exercises, you will utilize powerful command-line tools like ip, ifconfig, and nmcli to inspect interface details, verify their operational state, and gain insights into their configuration. By the end of this lab, you will be proficient in determining if a network interface is active and ready for communication.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/RemoteAccessandNetworkingGroup(["Remote Access and Networking"]) linux/RemoteAccessandNetworkingGroup -.-> linux/ifconfig("Network Configuring") linux/RemoteAccessandNetworkingGroup -.-> linux/ip("IP Managing") subgraph Lab Skills linux/ifconfig -.-> lab-558735{{"How to check if a network interface is active in Linux"}} linux/ip -.-> lab-558735{{"How to check if a network interface is active in Linux"}} end

In this step, you will learn how to check the status of network interfaces on your Linux system using the ip link show command. Network interfaces are the points where your computer connects to a network, like Wi-Fi or Ethernet.

The ip command is a powerful tool for network configuration in Linux. The link subcommand is used to manage network devices, and show displays information about them.

Open the terminal if you haven't already. You can do this by clicking the Xfce Terminal icon on the left side of your desktop.

Now, type the following command into the terminal and press Enter:

ip link show

You will see output similar to this:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff

Let's break down the output:

  • 1: lo:: This is the loopback interface. It's a virtual interface that your computer uses to communicate with itself. It's always "up" and running.
  • 2: eth0:: This is likely your primary network interface, often representing an Ethernet connection.
  • <BROADCAST,MULTICAST,UP,LOWER_UP>: These are flags indicating the capabilities and current state of the interface. UP and LOWER_UP mean the interface is active and ready to send and receive data.
  • mtu 1500: Maximum Transmission Unit, the largest packet size that can be sent without fragmentation.
  • qdisc mq: Queueing discipline, which manages how packets are sent.
  • state UP: The current operational state of the interface.
  • mode DEFAULT: The operating mode.
  • group default: The group the interface belongs to.
  • qlen 1000: The transmit queue length.
  • link/ether 02:42:ac:11:00:02: The MAC address of the interface.

The ip link show command is a fundamental tool for quickly checking the status and basic information of your network interfaces.

Click Continue to proceed to the next step.

Verify interface with ifconfig output

In this step, you will use the ifconfig command to view network interface information. While ip is the modern standard, ifconfig is still commonly encountered and provides similar details about your network interfaces.

The ifconfig command is used to configure or view the configuration of a network interface. When used without any arguments, it displays the status of all active network interfaces.

Type the following command into your terminal and press Enter:

ifconfig

You will see output similar to this:

eth0: flags=... mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 1000  (Ethernet)
        RX packets ... bytes ...
        RX errors ... dropped ... overruns ... frame ...
        TX packets ... bytes ...
        TX errors ... dropped ... overruns ... carrier ... collisions ...

lo: flags=... mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets ... bytes ...
        RX errors ... dropped ... overruns ... frame ...
        TX packets ... bytes ...
        TX errors ... dropped ... overruns ... carrier ... collisions ...

Let's look at the key information provided by ifconfig:

  • eth0: and lo:: The names of the network interfaces.
  • flags=...: Similar to the flags in ip link show, indicating the interface's state and capabilities.
  • inet 172.17.0.2: The IPv4 address assigned to the interface.
  • netmask 255.255.0.0: The network mask, used to determine the network and host portions of the IP address.
  • broadcast 172.17.255.255: The broadcast address for the network.
  • ether 02:42:ac:11:00:02: The MAC address of the interface.
  • RX packets ... bytes ...: Statistics about received packets and bytes.
  • TX packets ... bytes ...: Statistics about transmitted packets and bytes.

Comparing ifconfig and ip link show, you can see they provide similar information but with different formatting. ifconfig is often preferred for quickly seeing IP addresses and network masks, while ip is more versatile for various network configurations.

Practice using both commands to become familiar with their output.

Click Continue to move to the next step.

Inspect interface details using nmcli

In this step, you will explore network interface details using the nmcli command. nmcli is a command-line tool for controlling NetworkManager, a service that manages network connections on many Linux systems. It provides a more user-friendly way to interact with network settings compared to ip or ifconfig for some tasks.

To view a summary of your network devices using nmcli, type the following command and press Enter:

nmcli device status

You will see output similar to this:

DEVICE  TYPE      STATE      CONNECTION
eth0    ethernet  connected  Wired connection 1
lo      loopback  unmanaged  --

This output shows the device name (DEVICE), its type (TYPE), its current state (STATE), and the active connection (CONNECTION).

To get more detailed information about a specific interface, you can use nmcli device show followed by the interface name. Let's look at the details for eth0.

Type the following command and press Enter:

nmcli device show eth0

You will see extensive output providing details about the eth0 interface, including its hardware address, IP addresses, DNS servers, and more. The output will look something like this (parts are omitted for brevity):

GENERAL.DEVICE:                         eth0
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         02:42:AC:11:00:02
GENERAL.STATE:                          100 (managed)
GENERAL.CONNECTION:                     Wired connection 1
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/1
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         172.17.0.2/16
IP4.GATEWAY:                            172.17.0.1
IP4.ROUTE[1]:                           dst = 172.17.0.0/16, nh = 0.0.0.0, mt = 100
IP4.DNS[1]:                             ...
IP6.ADDRESS[1]:                         ...
IP6.GATEWAY:                            ...

nmcli is particularly useful for scripting network configurations and for users who prefer a more structured output than ifconfig.

You have now learned three different commands (ip link show, ifconfig, and nmcli) to inspect network interfaces in Linux. Each command provides similar information but with different levels of detail and formatting.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check the status of network interfaces in Linux using various command-line tools. You first explored the ip link show command, a powerful tool for displaying detailed information about network devices, including their state (UP or DOWN) and capabilities. This command provides a comprehensive overview of all available interfaces, such as the loopback interface (lo) and your primary network interface (e.g., eth0).

By examining the output of ip link show, you can identify key flags like UP and LOWER_UP to confirm if an interface is active and ready for communication. This initial step provides a fundamental understanding of your system's network connectivity at the link layer.