How to Find Your MAC Address on Linux
Reading Time: 4 minutesMAC addresses are used to identify devices connected to a network. There are several ways you can find your MAC address on Linux.
If you are administering a Linux system, there will likely be times when you need to know your system’s MAC address. You may need this information for several reasons. Perhaps you want DHCP to assign you a fixed IP address. For this, you will need the MAC address so that you can add the IP and MAC address mapping to your DHCP server configurations.
You may also need this information for MAC address filtering to allow or block certain devices on your network. Or maybe you want to set up Wake-on-LAN. Whatever the reason is, here are a few different ways to find the MAC address on your Linux system.
What Is a MAC Address?
A MAC address, also known as a physical or hardware address, is a unique identifier associated with a network interface card of pretty much every device connected to a network.
MAC address functions at the second layer (Data Link layer) of the OSI model and is 48 bits in length, where the first 24 bits represent the manufacturer ID and the last 24 bits represent the unique ID for that NIC. Like IP addresses, you can also change the MAC address of your NIC.
Find the MAC Address on Linux via the Command Line
Here are a few quickest and easiest methods to find your MAC address on Linux:
Using the ip Command
You can use the ip command in Linux to view and configure physical as well as virtual network interfaces, routing, policy routing, and tunnels. It can add or delete a network interface, assign/remove IP addresses, display the status of network interfaces, and perform much more useful tasks.
You can find the MAC address of your system using the following ip command:
ip link show
This command shows the details of all the network interfaces including their MAC addresses besides the label link/ether as highlighted below:
To find the MAC address of a particular network interface, use the following syntax:
ip link show dev
Using the ifconfig Command
The ifconfig command in Linux allows you to configure and display the status of network interfaces. Moreover, it can also activate and deactivate a network interface.
To find the MAC address of all the available network interfaces (even if they are deactivated), use the ifconfig command with the -a flag as follows:
ifconfig -a
To find the MAC address of a particular network interface, specify its name as an argument:
ifconfig interface_name
To find the MAC address of all the currently active network interfaces, use the ifconfig command without any flag:
ifconfig
In the output, you can find the MAC address of your interface beside the label ether as highlighted below:
Using the ethtool Utility
ethtool is a Linux utility that allows you to query and configure network drivers and network interface card settings. Using the ethtool utility, you can also query a network interface for its MAC address.
Here’s the command to do so:
ethtool -P interface_name
Get MAC Address From the /sys/class/net Directory
The /sys/class/net directory contains information about the network devices attached to the system. This directory maintains a separate subdirectory for each of the network interfaces like /sys/class/net/ens33 and /sys/class/net /ens37.
Each subdirectory contains different files for each network attribute like MAC address, the operational state of the network device, its duplex, MTU, etc. The MAC address information is stored in the address file.
To list the network interfaces attached to your system, use the following command:
ls /sys/class/net
To find the MAC address of a particular network interface, use the following command syntax:
cat /sys/class/net/interface_name/address
For instance, to find the MAC address of a network interface, let’s say ens33, the command would be:
cat /sys/class/net/ens33/address
How to Find the MAC Address on Linux via GUI
Those who prefer GUI for their routine tasks can find their MAC address graphically using the network manager provided by their distribution. Like in Ubuntu, you can use the Network Connections settings.
Open Settings in your Linux distribution either by right-clicking on your desktop or from the applications menu. From the left panel, go to the Network tab. This will display all the network interfaces attached to your system.
To find the MAC address of a network interface, click the Cog (settings) icon in front of it.
This will open a new window showing the details of your network interface. Here you will find the MAC address beside the label Hardware Address.
For this guide, we’ve used GNOME for the images, but other desktop environments would also have similar settings, only with different labels.
Find the MAC Address of Another System on a Local Network
Similar to your own MAC address, you can also find the MAC address of other systems on a local network. Here’s how:
Using the arp Command
You can use ARP, or Address Resolution Protocol, to learn the MAC address for a given IP address. To find the MAC address of another system on a local network, ping its IP address with:
ping -c1 <IP address>
The ping command will use ARP to learn the MAC address of the remote system. Once it gets this information, it’s stored in the ARP table, which you can view using:
arp -n | grep <IP address>
This command will print the MAC address for the given IP address.
Using the arping Utility
The arping utility helps you discover and probe local systems on a network. It functions at the second layer in the OSI model and sends the ARP request to the system to determine whether it is alive and responding. It is different from the ping utility which functions at the third layer.
You can install arping using the following commands:
On Debian-based distributions:
sudo apt install arping
On RHEL-based distributions:
sudo yum install arping
Once installed, find the MAC address of another system on a network by specifying its IP address as an argument using the following command:
sudo arping -c 1 <IP address>
If your system has multiple NICs, you can specify from which interface a request should be sent using the -I flag (capital ‘i’) followed by the interface name:
sudo arping -c 1 -I interface_name <IP address>
For instance, the following command will send one ARP request from its ens33 interface to the remote system’s IP address 192.168.42.133.
sudo arping -c 1 -I ens33 192.168.42.133
In the output, you will receive the ARP reply from the destination system containing its MAC address.
It’s Easy to Find Your MAC Address on Linux
Given the various methods of finding the MAC address on Linux, you can pick and choose any one that you find convenient.
Similar to Linux, you can also find the MAC address in Windows and macOS; however, they have different sets of commands and GUI.
Reference: https://www.makeuseof.com/find-your-mac-address-on-linux/
Ref: makeuseof