List network interfaces on Linux

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.

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

Screenshot showing ip command, an alternative to ifconfig

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.

ifconfig -l

Frequently Asked Questions

How can I see the MTU of an interface?

Use the ip show link command.

ip show link <interface>

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. This is typically stored in the /etc/resolv.conf file. 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.

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also a cheat sheet available.

  • column
  • ifconfig
  • ipcheat sheet
  • netstat

Related articles

Like to learn more? Here is a list of articles within the same category or having similar tags.

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon