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.
Table of Contents
Show network interfaces
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
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
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 126.96.36.199 dev eth0 onlink 10.17.0.0/16 dev eth0 proto kernel scope link src 10.17.0.3 188.8.131.52/18 dev eth0 proto kernel scope link src 184.108.40.206
The default gateway can be listed with the netstat command.
The output will be something like this:
Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface default 220.127.116.11 0.0.0.0 UG 0 0 0 eth0 10.17.0.0 * 255.255.0.0 U 0 0 0 eth0 18.104.22.168 * 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.
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, 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!