How to check Network Interface Card information in Linux

Server primary interface would be configured as part of the server build activity, but sometimes you may need to configure an additional network interface in Linux for several reasons.

An additional interface will be configured for network bonding/teaming, high availability or a separate interface that is used for application requirements or backups.

Before adding a new interface, check if the system has any free interfaces. If yes, check other configuration details that are compatible with existing interfaces.

In this tutorial, we will show you how to check the available Network Interface Card (NIC) and other details such as interface name, associated IP address, MAC address and interface speed.

What is IP command?

IP command is similar to ifconfig, which is used for assigning Static IP Address, Route & Default Gateway, etc.

# ip a

1: lo: mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether fa:16:3e:a0:7d:5a brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.101/24 brd 192.168.1.101 scope global eth0
    inet6 fe80::f816:3eff:fea0:7d5a/64 scope link
       valid_lft forever preferred_lft forever

What is ethtool command?

The ethtool command is used to query or control network driver and hardware settings.

# ethtool eth0

1) Checking available network interfaces

When you run the IP command without any argument, it gives you plenty of information about NIC, but use the following customized IP command to check only the network interfaces available on the system:

# ip a |awk '/state UP/{print $2}'

eth0:
eth1:

2) Checking IP address of the network interface

Run the below command to check the active network interface and the associated IP address:

# ip -o a show | cut -d ' ' -f 2,7
or
# ip a |grep -i inet | awk '{print $7, $2}'

lo 127.0.0.1/8
lo ::1/128
wlp8s0 192.168.1.6/24
wlp8s0 fe80::70fd:ea3a:2985:87fe/64
docker0 172.17.0.1/16

3) Check the MAC address of the NIC

Run the below commands to check the active network interface and the associated MAC address.

To verify the specific network interface MAC address, run the below command:

# ip link show dev eth0 |awk '/link/{print $2}'
00:00:00:55:43:5c

I did not find options to verify the MAC address of all network interfaces at once, so we created the following script to see them all:

# vi /opt/scripts/mac-addresses.sh

#!/bin/sh
ip a |awk '/state UP/{print $2}' | sed 's/://' | while read output;
do
echo $output:
ethtool -P $output
done

Run the following shell script to check the MAC address of multiple network interfaces:

# sh /opt/scripts/mac-addresses.sh

eth0:
Permanent address: 00:00:00:55:43:5c
eth1:
Permanent address: 00:00:00:55:43:5d

4) Check the speed of the network interface port

Network interface port speed can only be verified in Linux using the ‘ethtool’ command.

To check the speed of a particular network interface port, use the following command:

# ethtool eth0 |grep "Speed:"

Speed: 10000Mb/s

ethtool does not have the option to display all NIC speeds at once, so we created the following script to view them all:

# vi /opt/scripts/port-speed.sh

#!/bin/sh
ip a |awk '/state UP/{print $2}' | sed 's/://' | while read output;
do
echo $output:
ethtool $output |grep "Speed:"
done

Run the following shell script to check the NIC port speed of all network interfaces:

# sh /opt/scripts/port-speed.sh

eth0:
Speed: 10000Mb/s
eth1:
Speed: 10000Mb/s

5) Shell Script to Verify Network Interface Card Information

The following shell script gathers all the necessary information about NIC at once, such as network interface names, IP addresses of network interfaces, MAC addresses of network interfaces, and the speed of a network interface port:

# vi /opt/scripts/nic-info.sh

#!/bin/sh
hostname
echo "-------------"
for iname in $(ip a |awk '/state UP/{print $2}')
do
echo "$iname"
ip a | grep -A2 $iname | awk '/inet/{print $2}'
ip a | grep -A2 $iname | awk '/link/{print $2}'
ethtool $iname |grep "Speed:"
done

Run the below shell script to check all the required information about the network interface:

# sh /opt/scripts/nic-info.sh

vps.2daygeek.com
----------------
eth0:
192.168.1.101/24
00:00:00:55:43:5c
Speed: 10000Mb/s
eth1:
192.168.1.102/24
00:00:00:55:43:5d
Speed: 10000Mb/s

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *