How to check Network Interface Card (NIC) information on Linux

By default when you set up the server you will configure the primary network interface.

This is part of the build work that everyone does.

Sometimes you may need to configure an additional network interface for several reasons.

This could be a network bonding/teaming or high availability or a separate interface for application requirements or backups.

To do so, you need to know how many interfaces your computer has and their speed to configure it.

There are many commands to check for available network interfaces, but we only use the IP command.

Later we will write a separate article with all these tools.

In this tutorial, we will show you the Available Network Interface Card (NIC) information, such as the interface name, associated IP address, MAC address, and interface speed.

What is IP command?

IP command is similar to ifconfig, which is used to 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 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 arguments, it gives you plenty of information, but if you only need the available network interfaces, use the following customized IP command.

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

eth0:
eth1:

2) Check the IP address of the network interface

If you only want to see which IP address is assigned to which interface, use the following customized IP command.

# 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
192.168.1.101/24
192.168.1.102/24

3) Check the MAC address of the NIC

If you only want to see the network interface name and the corresponding MAC address, use the following format.

To check a specific network interface MAC address.

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

To check MAC address for all network interface.

# 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 below shell script to get the MAC address for 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

If you want to check the network interface port speed on Linux, use the ethtool command.

To check the speed of a particular network interface port.

# ethtool eth0 |grep "Speed:"

Speed: 10000Mb/s

To check the port speed for all network interfaces.

# 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 below shell script to get the port speed for multiple 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

This shell script allows you to gather all of the above information, 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 network card information.

# 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 *