Method 1: Pass the /sys file system
The /sys file system provides a way to access and control hardware devices.
Detailed information for each network interface can be found in the /sys/class/net/ directory.
cat /sys/class/net/eth0/address
Replace eth0 with the name of the network interface you want to query. This outputs the MAC address of the interface.
Method 2: Use the ip command, need to be installed
1. Install the ip command
sudo yum install iproute
Centos cloud installation
2. Query ip link show
ip link show
eth0 corresponds to the physical address
The format is xx:xx:xx:xx:xx:xx:xx
Method 3: Use ipconfig, you need to install it
ifconfig eth0 | grep -i hwaddr
In the output result, find the network card name you want to view the MAC address, such as eth0, eth1, or enp0s3.
In the network card information, find a field similar to HWaddr or ether, and the following value is the MAC address of the network card.
Method 4: Use nmcli command
nmcli device show
In the output, find the device you want to view the MAC address
The HWADDR field, the following value is the MAC address
This is the end of this article about the implementation of Linux querying the physical address of mac. For more related contents of Linux querying the physical address of mac, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!