A MAC (Media Access Control) address is a unique value assigned to a network interface card (NIC, also called network adapter) by the manufacturer to uniquely identify it. This tutorial provides 2 methods how to get MAC address in the Linux.
Method 1 - ip command
The ip
command can be used to manage network interfaces. The following command prints the MAC address of each network interface:
ip -o link show | cut -d ' ' -f 2,20
Output example:
lo: 00:00:00:00:00:00
ens33: 00:0c:29:2f:d4:6a
Method 2 - /sys/class/net directory
The directory /sys/class/net
contains information about the network interfaces available in the system. The following command allows getting MAC address of each network interface:
cat /sys/class/net/*/address
Output example:
00:0c:29:2f:d4:6a
00:00:00:00:00:00
To get the MAC address of a specific network interface, use the following command:
cat /sys/class/net/ens33/address
Leave a Comment
Cancel reply