Which Linux command would you use to check configuration of network interfaces?

The network configuration is a common place to start during system configuration, security audits, and troubleshooting. It can reveal useful information like MAC and IP addresses. This guide helps you to gather this information on Linux, including listing all available network interfaces and its details.

Table of Contents

  • Show network interfaces
    • Linux
      • The old way: ifconfig
      • Modern version: using the ip command
      • Show the default gateway
        • Using the ip command
        • With netstat
    • AIX and Solaris
    • DragonBSD, FreeBSD, NetBSD
  • Frequently Asked Questions
    • How can I see the MTU of an interface?
    • What command can I use to display the default gateway on Linux?
    • How can I test if my network configuration is correct?

Show network interfaces

Linux

Every Linux distribution is using its own way of configuring the network configuration details. Therefore, it is good to know which tools can be used to query these details in a generic way. So these commands should be working on the popular distributions like Arch Linux, CentOS, Debian, Gentoo, RHEL, and Ubuntu.

The old way: ifconfig

Previously the most obvious command to obtain the available network interfaces was using the ifconfig command. As some systems no longer have that command installed by default, we will also look at using alternative ip. If you still have ifconfig available, run it with the -a parameter.

ifconfig -a | grep Link

Depending on what particular information you need, you can use grep to get you the right lines. The ifconfig command on Linux actually has the most option available, so have a look at the man page for all details.

Modern version: using the ip command

Newer Linux distributions now ship only the ip command. It is advised to start using this command instead of ifconfig, as its output works better with newer machines. Especially when using containerized applications, dynamic routing, and network aliases.

The easiest way to see what network interfaces are available is by showing the available links.

ip link show

Which Linux command would you use to check configuration of network interfaces?

Linux network interfaces with ip link show command

Another option to show available network interfaces is by using netstat.

netstat -i | column -t

Note: the column command is optional, but provides a friendlier output for the eye.

Show the default gateway

The default gateway is the system that receives traffic for networks outside your own. On Linux systems, this gateway is typically received via DHCP or manually configured in a text configuration file.

Using the ip command

ip route | column -t

The output may look like this:

default        via 123.12.0.1 dev   eth0   onlink
10.17.0.0/16   dev eth0       proto kernel scope  link src 10.17.0.3
123.12.0.0/18  dev eth0       proto kernel scope  link src 123.123.0.3
With netstat

The default gateway can be listed with the netstat command.

netstat -r

The output will be something like this:

Kernel IP routing table
Destination      Gateway       Genmask        Flags  MSS  Window irtt  Iface
default          123.12.0.1    0.0.0.0        UG     0    0      0     eth0
10.17.0.0        *             255.255.0.0    U      0    0      0     eth0
123.12.0.0       *             255.255.192.0  U      0    0      0     eth0

The second column shows the gateway. When it lists an asterisk (*), it means it uses the default gateway.

AIX and Solaris

These two old style platforms have of course ifconfig still available. By using the -a parameter, all interfaces will be displayed.

ifconfig -a | grep "flags="

To see only the interfaces which are active, add the -u (up) parameter.

DragonBSD, FreeBSD, NetBSD

On the systems running BSD, it is also the ifconfig tool that can be used.

Kernel IP routing table
Destination      Gateway       Genmask        Flags  MSS  Window irtt  Iface
default          123.12.0.1    0.0.0.0        UG     0    0      0     eth0
10.17.0.0        *             255.255.0.0    U      0    0      0     eth0
123.12.0.0       *             255.255.192.0  U      0    0      0     eth0
0

 

Frequently Asked Questions

How can I see the MTU of an interface?

Use the ip show link command.

Kernel IP routing table
Destination      Gateway       Genmask        Flags  MSS  Window irtt  Iface
default          123.12.0.1    0.0.0.0        UG     0    0      0     eth0
10.17.0.0        *             255.255.0.0    U      0    0      0     eth0
123.12.0.0       *             255.255.192.0  U      0    0      0     eth0
1

What command can I use to display the default gateway on Linux?

Use the ip route command to show routing information, including the default gateway and the network interface it uses.

How can I test if my network configuration is correct?

Test if you can reach or access both devices on your network as outside of it. This way you know that your IP address and gateway is correctly set up. If you can only access remote systems by IP address, then check your name server configuration, typically stored in /etc/resolv.conf. Another useful tool to test your system, including your network configuration, is by using auditing tool Lynis. It will test for connectivity of the name servers and retrieves the most important parts of the network settings.

 

Did this article help you? Become part of the community and share it on your favorite website or social media. Do you have additional tips regarding the network configuration on Linux? Share it in the comments!

Which Linux command shows network interface configurations?

The “ifconfig” command is used for displaying current network configuration information, setting up an ip address, netmask, or broadcast address to a network interface, creating an alias for the network interface, setting up hardware address, and enable or disable network interfaces.

What command is used to check the network interfaces?

You can view the settings of all interfaces or a specific interface by using the ifconfig command.