Home Linux Networking How To Find Available Network Interfaces On Linux

How To Find Available Network Interfaces On Linux

List Ethernet Cards In Linux And Unix

By sk
Published: Last Updated on 29,075 Views

We can configure network interfaces in Linux during the installation time. But, some of you might prefer to do it after installation or change the existing settings. As you know already, you must first know how many interfaces are available on the system in-order to configure network settings from command line. This detailed tutorial addresses all the possible ways to list and find available network interfaces on Linux and Unix operating systems.

Find available network interfaces in Linux

We can find the available network cards in couple ways. In this guide, we will discuss 10 ways to list network interface cards in Linux.

1. List network interfaces using ifconfig command

The most commonly used method to find the network interface details using ifconfig command. I believe some of Linux users might still use this.

$ ifconfig -a

Sample output:

enp5s0: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 24:b6:fd:37:8b:29 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 171420 bytes 303980988 (289.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 171420 bytes 303980988 (289.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlp9s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.225.37 netmask 255.255.255.0 broadcast 192.168.225.255
inet6 2409:4072:6183:c604:c218:85ff:fe50:474f prefixlen 64 scopeid 0x0<global>
inet6 fe80::c218:85ff:fe50:474f prefixlen 64 scopeid 0x20<link>
ether c0:18:85:50:47:4f txqueuelen 1000 (Ethernet)
RX packets 564574 bytes 628671925 (599.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 299706 bytes 60535732 (57.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

As you see in the above output, I have two network interfaces namely enp5s0 (on board wired ethernet adapter) and wlp9s0 (wireless network adapter) on my Linux box. Here, lo is loopback interface, which is used to access all network services locally. It has an IP address 127.0.0.1.

We can also use the same 'ifconfig' command in many UNIX variants, for example FreeBSD, to list available network cards.

2. List network interfaces using ip command

The 'ifconfig' command is deprecated in the latest Linux versions. So you can use 'ip' command to display the network interfaces as shown below.

$ ip link show

Sample output:

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: enp5s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 24:b6:fd:37:8b:29 brd ff:ff:ff:ff:ff:ff
3: wlp9s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000
    link/ether c0:18:85:50:47:4f brd ff:ff:ff:ff:ff:ff
Find available network interfaces with 'ip' command
Find available network interfaces with 'ip' command

You can also use the following commands as well.

$ ip addr
$ ip -s link

Did you notice that these command also shows the connected state of the network interfaces? If you closely look at the above output, you will notice that my Ethernet card is not connected with network cable (see the word "DOWN" in the above output). And wireless network card is connected (See the word "UP"). For more details, check our previous guide to find the connected state of network interfaces on Linux.

These two commands (ifconfig and ip) are just enough to find the available network cards on your Linux systems.

However, there are few other methods available to list network interfaces on Linux.

3. List network interfaces using /sys/class/net/ directory

The Linux Kernel saves the network interface details inside /sys/class/net directory. You can verify the list of available interfaces by looking into this directory.

$ ls /sys/class/net

Sample output:

enp5s0  lo  virbr0  wlp9s0

4. List network interfaces using /proc/net/dev file

In Linux operating systems, /proc/net/dev file contains statistics about network interfaces.

To view the available network cards, just view its contents using command:

$ cat /proc/net/dev

Sample output:

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:    2836      30    0    0    0     0          0         0     2836      30    0    0    0     0       0          0
enp5s0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
wlp9s0: 557664882  402062    0    0    0     0          0         0 20087136  165358    0    0    0     0       0          0
virbr0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

5. List network interfaces using netstat command

The netstat command displays various details such as network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

$ netstat -i

Sample output:

Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
enp5s0           1500        0      0      0 0             0      0      0      0 BMU
lo              65536       30      0      0 0            30      0      0      0 LRU
virbr0           1500        0      0      0 0             0      0      0      0 BMU
wlp9s0           1500   402063      0      0 0        165361      0      0      0 BMRU

Please be mindful that netstat is obsolete. The Replacement for "netstat -i" is "ip -s link". Also note that this method will list only the active interfaces, not all available interfaces.

6. List network interfaces using nmcli command

The nmcli is a command-line tool for controlling NetworkManager and reporting network status. It is used to create, display, edit, delete, activate, and deactivate network connections and display network status.

If you have Linux system with Network Manager installed, you can list the available network interfaces using nmcli tool using the following commands:

$ nmcli device status

Sample output:

DEVICE          TYPE      STATE                   CONNECTION    
wlp9s0          wifi      connected               JioFi4_12E9FE 
virbr0          bridge    connected (externally)  virbr0        
p2p-dev-wlp9s0  wifi-p2p  disconnected            --            
enp5s0          ethernet  unavailable             --            
lo              loopback  unmanaged               --            

You can also use this command to show network interfaces in your Linux system:

$ nmcli connection show

Most of the aforementioned utilities comes pre-installed in most Linux and Unix systems. There are also a few more external utilities available to show list of network cards.

7. Show list of network interfaces using hwinfo

Hwinfo is a command line utility to view the hardware information in a Linux system. It probes for the hardware present in a Linux system and displays the extensive details of each hardware device.

Hwinfo is available in the official repositories of many Linux distributions. To install hwinfo on RPM-based systems, run:

$ sudo dnf install hwinfo

On Deb-based systems, you can install hwinfo using the following command:

$ sudo apt install hwinfo

Once installed, run the following command to list the name of the network interfaces using hwinfo utility:

$ sudo hwinfo --short --network

Sample output:

network interface:                                              
  enp5s0               Ethernet network interface
  virbr0               Ethernet network interface
  wlp9s0               Ethernet network interface
  lo                   Loopback network interface

8. Show network interfaces using lshw

Lshw (Hardware Lister) is a CLI utility that provides detailed information of the hardware configuration of a Linux system.

To show the list of network cards in Linux with lshw utility, run:

$ sudo lshw -class network -short

Sample output:

H/W path                 Device      Class          Description
===============================================================
/0/100/1c.1/0            enp5s0      network        RTL810xE PCI Express Fast Ethernet controller
/0/100/1c.3/0            wlp9s0      network        AR9285 Wireless Network Adapter (PCI-Express)

9. View network interfaces using inxi

Inxi is yet another command line system information tool like hwinfo and lshw. It shows system hardware, CPU, drivers, Xorg, Desktop, Kernel, GCC version(s), Processes, RAM usage, and a wide variety of other useful information.

To show information about the network cards, including the vendor, card driver and number of available network interfaces in a Linux system, run inix with -N option:

$ inxi -N
Network:   Device-1: Realtek RTL810xE PCI Express Fast Ethernet driver: r8169 
           Device-2: Qualcomm Atheros AR9285 Wireless Network Adapter driver: ath9k 

10. Display network interfaces using lspci

The lspci command lists all PCI devices in a Linux system.

To view the list of available network interfaces in a Linux system, use lspci with egrep command like below:

$ lspci | egrep -i 'network|ethernet|wireless|wi-fi'

Sample output:

05:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL810xE PCI Express Fast Ethernet controller (rev 05)
09:00.0 Network controller: Qualcomm Atheros AR9285 Wireless Network Adapter (PCI-Express) (rev 01)

List only the name of available network interfaces

What we have seen so far is various methods to find the available network interfaces in Linux. In all of the aforementioned methods, we displayed the available network interfaces along with some additional details, such as RX/TX details, Mac address, connected state, mode, type of the network and a few more. If you want to strip unnecessary details and list only the name of the network interfaces, you can use one of the following commands.

$ ifconfig -a | sed 's/[ \t].*//;/^$/d'

Sample output:

enp5s0:
lo:
virbr0:
wlp9s0:

To exclude the loopback device (lo) from the output, run this command instead:

$ ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\)$/d'

As stated earlier, ifconfig command is deprecated. If ifconfig command is not available, use ip command to display only the name of the network interfaces with -o flag like below:

$ ip -o link show | awk -F': ' '{print $2}'
lo
enp5s0
wlp9s0
virbr0

You can also use the following command as well:

$ ip addr show | awk '/^[1-9]/ {print $2}'

Conclusion

In this guide, we discussed ten different methods to find and list the available network interfaces on Linux and Unix. We've also looked at a few ways to display only the name of the network interfaces in Linux.

Check the following guides to know how to configure IP address on Linux.

You May Also Like

2 comments

01101001b March 5, 2019 - 2:17 am

Very interesting article! Thank you!

As a matter of fact, I find it difficult to understand why good tools like netstat and ifconfig are deemed “outdated” or “deprecated” if they work well even today. I don’t reject new tools, even if they do something quite similar to existing ones, but if something is obsolete, it’ll disappear by itself.

Change is ok. But to change something just because, for the change in itself, sounds much like Wind*ws users’ mentality to me. New? Old? What matters? The important thing is the tool is still useful. Just my two cents. Regards!

Reply
sk March 5, 2019 - 12:15 pm

Completely agree with your point. I still use some of the deprecated tools, like ifconfig and netstat. Old habits die hard.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More