Home >Operation and Maintenance >Linux Operation and Maintenance >What is the command to check mac address in linux?
Linux commands to check the mac address include: "ifconfig -a" command, "cat /sys/class/net/eth0/address" command, "dmesg | grep eth0" command, "cat /proc/net" /arp" command, etc.
How to check the mac address in linux
PS: Generally, the default network card file name It is eth0. Just judge it is ethx based on the actual situation corresponding to the IP address.
1, ifconfig -a
The HWaddr field is the MAC address, which is the most commonly used method
2, cat /etc/sysconfig/network-scripts/ifcfg-eth0
(CentOS or Redhat configuration file)
below Both types can be viewed before IP is set. Can be used to solve the problem of binding between MAC and operating system. For example, if you install the operating system to a remote server, the mac address of the operating system is the address of host A. On host B, it cannot be started remotely because the MAC address is different (because the configuration file is still the mac address of A at this time). Since the OS will detect the hardware when it starts, obtain the MAC address of the hardware, and write it to the /sys/class/net/eth0/address file, we will use the original MAC configuration file after the OS obtains the mac address (that is, /etc /sysconfig/network-scripts/ifcfg-eth0), write the real mac address into the configuration file.
3, cat /sys/class/net/eth0/address
Check the MAC address of eth0
4, dmesg | grep eth0
dmesg' command is very important to diagnose device faults. When performing hardware connection or disconnection operations with the help of the 'dmesg' command, we can see the hardware detection or disconnection information.
5、cat /proc/net/arp
Check the MAC address of the remote IP connected to this machine
You cannot see the MAC of the local machine, you can only see the remote connection, which is mostly used on the server side.
6. Use the ioctl command of SIOCGIFHWADDR in the program to obtain the MAC address
Related recommendations: "Linux Video Tutorial》
The above is the detailed content of What is the command to check mac address in linux?. For more information, please follow other related articles on the PHP Chinese website!