1. Introduction to MAC address
A MAC address is a 48-bit unique identifier, usually expressed in hexadecimal form, e.g.00:1A:2B:3C:4D:5E
. It is solidified in the physical interface of the network device (such as a network card) and is used to identify the device in a local area network (LAN). Unlike IP addresses, the MAC address is a hardware-level identifier and does not change due to changes in network configuration. Therefore, it plays an important role in network management, such as for device identification, access control, and network troubleshooting.
2. Common methods to view the MAC address of Linux server
In Linux systems, there are several ways to view MAC addresses. These methods have their own characteristics and are suitable for different scenarios and user needs. The following are several common methods and detailed descriptions.
(I) Use ifconfig command
ifconfig
(Interface Configuration) is a traditional network configuration tool that displays and configures the parameters of a network interface. Although in modern Linux distributions,ifconfig
Has beenip
Commands are gradually replaced, but it is still a familiar tool for many system administrators.
-
Operation steps
Open the terminal.
Enter the following command and press Enter:
ifconfig
Output example:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 ether 00:1a:2b:3c:4d:5e txqueuelen 1000 (Ethernet) RX packets 100 bytes 12345 (12.3 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 100 bytes 12345 (12.3 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
In the output,
ether
The MAC address is displayed after the field.-
Applicable scenarios
- Suitable for scenarios where you need to quickly view the network interface configuration.
- Applicable to
ifconfig
Command more familiar users.
-
Things to note
In some modern Linux distributions, such as Ubuntu 18.04 and above,
ifconfig
It may not be installed by default. It can be installed through the following command:
sudo apt-get install net-tools
(II) Use the ip command
ip
Command is a more powerful network configuration tool, which can be used as a substitute.ifconfig
, and more advanced features are also provided.ip
Commands are recommended tools in modern Linux systems because they are more flexible and support more networking capabilities.
Operation steps
Open the terminal.
Enter the following command and press Enter:
ip link show
Output example:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 00:1a:2b:3c:4d:5e brd ff:ff:ff:ff:ff:ff
In the output,
link/ether
The MAC address is displayed after the field.-
Applicable scenarios
- Suitable for scenarios where you need to view the details of the network interface.
- Applicable to
ip
Command more familiar users.
-
Things to note
-
ip
The output information of the commandifconfig
More detailed, including interface status, queue length and other information. -
ip
Commands support multiple subcommands, for exampleip addr
Used to view IP addresses,ip route
Used to view routing information.
-
(III) View through system files
Linux systems store a lot of hardware information in specific files, which are located in/sys
In the directory. By viewing these files, you can directly obtain the MAC address.
-
Operation steps
Open the terminal.
Enter the following command and press Enter:
cat /sys/class/net/eth0/address
Output example:
00:1a:2b:3c:4d:5e
Here
eth0
It is the name of the network interface, and replace it with your interface name according to the actual situation (such aswlan0
、ens33
wait).-
Applicable scenarios
- Suitable for scenarios where MAC addresses need to be obtained through script automation.
- Suitable for users who are familiar with the underlying file structure of the system.
-
Things to note
-
/sys/class/net/<interface>/address
The MAC address is directly stored in the file, without the need to parse other information. - The advantage of this method is that it is simple and efficient, but requires users to understand the file structure of the Linux system.
-
(IV) Use nmcli command
nmcli
(NetworkManager Command Line Interface) is a command line tool for NetworkManager to manage and monitor network configuration. It is suitable for systems that use NetworkManager to manage networks.
-
Operation steps
Open the terminal.
Enter the following command and press Enter:
nmcli device show
Output example:
: eth0 : ethernet : 00:1A:2B:3C:4D:5E : 100 (connected) : Wired connection 1
In the output,
The MAC address is displayed after the field.
-
Applicable scenarios
- Suitable for systems that use NetworkManager to manage networks.
- Suitable for scenarios where you need to view the detailed status of network devices.
-
Things to note
nmcli
The output information of the command is relatively detailed, including device status, connection information, etc.If NetworkManager is not installed in the system, you can install it through the package manager
sudo apt-get install network-manager
3. Application of MAC address in Linux server management
MAC addresses have many applications in network management, and the following are some common scenarios:
-
Equipment identification and management
- In a data center or enterprise network, a MAC address can be used to uniquely identify the device. With the MAC address, administrators can quickly locate equipment for easy management and maintenance.
- In a virtualized environment, MAC addresses can be used to distinguish between virtual machines and physical devices.
-
Network access control
- Many network devices (such as switches, routers) support access control based on MAC address. By configuring MAC address filtering rules, you can restrict network access to a specific device.
- In a wireless network, the MAC address can be used to restrict access to unauthorized devices.
-
Troubleshooting
- When there is a problem with the network connection, the MAC address can help administrators quickly locate the fault points. For example, by comparing the MAC address of the device with the MAC address table of the switch port, you can determine whether the device is properly connected to the network.
-
Security monitoring
- The MAC address can be used to monitor network traffic and detect abnormal behavior. For example, by analyzing changes in MAC addresses, abnormal replacements or cyber attacks can be found for devices.
4. Summary
Viewing MAC addresses on Linux servers is a basic network management task. Through the various methods described in this article, users can choose the appropriate method according to their needs. Whether using traditionalifconfig
Or modernip
Commands, or directly obtained through system files, can quickly and accurately obtain the MAC address. In addition, the importance of MAC addresses in network management cannot be ignored. They are not only unique identifiers for devices, but also play a key role in device management, security monitoring and troubleshooting.
With the continuous development of network technology, Linux systems are becoming more and more widely used in network management. Mastering the viewing methods and application scenarios of MAC addresses will help system administrators better manage and maintain the network environment. In our future work, we also need to continuously learn and explore more efficient network management tools and methods to deal with increasingly complex network needs.
The above is the detailed content of common methods for viewing the MAC address of Linux servers. For more information about viewing Linux MAC addresses, please follow my other related articles!