How to list MAC address on Linux is a commonly asked question during a Linux job interview. Here are some methods to get the MAC address. These commands are safe to run without changing anything.
The following commands can get you the MAC address of your network interface in Linux.
- ifconfig -a
- ifconfig eth0
- ip link show
- ip -o link show eth0
- ip -o link show |cut -d ‘ ‘ -f 2,20
- cat /sys/class/net/*/address
The procedure to check MAC address in Linux is as follows:
- Open the terminal application.
- Type ifconfig -a or ip link show or cat /sys/class/net/*/address command
- Press Enter to run the command.
- This command will display useful information about your network interfaces, including the MAC address.
What is MAC address?
From Wikipedia, A MAC address is the unique identifier that is assigned by the manufacturer to a piece of network hardware (like a wireless card or an ethernet card). MAC stands for Media Access Control, and each identifier is intended to be unique to a particular device.
The MAC address consists of six sets of two characters, each separated by a colon. 00:1B:44:11:3A:B7 is an example of a MAC address. The MAC address is usually printed on the card itself. The MAC address can also be found in the BIOS of the computer or device.
A MAC address can be used to uniquely identify a device on a network. This allows for better security and more efficient networking. MAC addresses are usually assigned by the manufacturer of the network adapter. However, it is possible to change the MAC address of a device.
Find MAC address with ifconfig command in Linux
The best Linux command to find MAC address is using ifconfig command. All we need is to open the terminal then type ifconfig -a in the prompt. The number next to ether is the MAC address. This command will list all the network interfaces on your Linux system and their Ip address, MTU size, etc.
# ifconfig -a
ens1f0: flags=4163 mtu 1500
inet 10.124.202.230 netmask 255.255.255.128 broadcast 10.124.202.255
ether 70:ca:9b:ce:67:ae txqueuelen 1000 (Ethernet)
RX packets 12187970 bytes 7390885300 (6.8 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16813496 bytes 16253942714 (15.1 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xb1960000-b197ffff
The “ifconfig” command is a command-line utility that is used to display information about your network interfaces. This command is available on most Unix-like operating systems, including Linux and macOS. We can also use ifconfig command to troubleshoot network issues.
Find MAC address with ip link show command in Linux
Another way to find MAC address in Linux is using “ip link show” command. The number next to link/ether is the MAC address. This command will list the interface status, MAC address, MTU size, etc.
# ip link show
1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens1f0: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 70:ca:9b:ce:67:ae brd ff:ff:ff:ff:ff:ff
To view information about a specific network link, you can use the “ip link show” command and the name of the network interface. For example, if you want to view information about the eth0 interface, you can run the following command: “ip link show eth0”.
The following command lists the interface names on the left and the associated MAC addresses on the right.
ip -o link show |cut -d ‘ ‘ -f 2,20
Find MAC address from /sys in Linux
If you want to get MAC information about the network interface, you can use this command cat /sys/class/net/*/address.
sysfs is a virtual filesystem in Linux that provides a way to access and manipulate the parameters of devices. sysfs is mounted on /sys when your system boots.
The sysfs filesystem contains a directory for each device on your system. The name of the directory is the name of the device. The contents of the directory depend on the type of device.If you want to get information about the network interfaces on your system, you can cd to /sys/class/net/.
# cat /sys/class/net/ens1f0/address
$ cat /sys/class/net/*/address
Difference between MAC address and IP address
MAC addresses are physical addresses, while ip addresses are logical addresses. MAC addresses are used to identify devices on a network, while ip addresses are used to identify the location of devices on a network.
The two most common types of ip addresses are IPv4 and IPv6. IPv4 is a 32-bit address that can support up to 4.3 billion unique addresses. IPv6 is a 128-bit address that can support up to 3.4×1038 unique addresses.
MAC addresses are assigned by the manufacturer of the device. Ip addresses can be assigned by the user or by the network administrator.