How to Find MAC Address in Linux

Posted on the 29 December 2022 by Top10

If you're administering a Linux system, there are bound to be times when you need to know your system's MAC address. This information may be needed for several reasons. Perhaps you want DHCP to assign you a fixed IP address. To do this, you will need a MAC address so that you can add an IP address to MAC address mapping in your DHCP server configuration.

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, 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 the network interface card of almost every device connected to a network.

The MAC address functions at the second layer (data link layer) of the OSI model and is 48 bits long, where the first 24 bits are the vendor ID and the last 24 bits are the unique ID for that NIC. As with IP addresses, you can change the MAC address of your network card.

Find the MAC address in Linux on the command line

Here are some of the fastest and easiest ways to find your MAC address on Linux:

Using the ip command

You can use the Linux ip command to view and configure physical and virtual network interfaces, routing, routing policies, and tunnels. It can add or remove a network interface, assign/remove IP addresses, display the status of network interfaces, and perform many more useful tasks.

You can find out the MAC address of your system with the following ip command:

ip link show

This command shows information about all network interfaces, including their MAC addresses, in addition to the link/ether label, as shown below:

To find the MAC address of a specific 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. In addition, it can also activate and deactivate the network interface.

To find out the MAC addresses of all available network interfaces (even if they are disabled), use the ifconfig command with the -a flag as follows:

ifconfig -a

To find out the MAC address of a specific network interface, specify its name as an argument:

ifconfig interface_name

To find out the MAC addresses of all currently active network interfaces, use the ifconfig command without any flags:

ifconfig

In the output, you can find the MAC address of your interface next to the ether label, as shown below:

Using the ethtool utility

ethtool is a Linux utility that allows you to query and configure network drivers and network card settings. You can also query a network interface for its MAC address using the ethtool utility.

Here is the command for this:

ethtool -P interface_name

Get MAC address from /sys/class/net directory

The /sys/class/net directory contains information about network devices connected to the system. This directory has a separate subdirectory for each of the network interfaces, such as /sys/class/net/ens33 and /sys/class/net/ens37.

Each subdirectory contains different files for each network attribute, such as MAC address, network device health, duplex, MTU, etc. MAC address information is stored in the file address.

To get a list of network interfaces connected to your system, use the following command:

ls /sys/class/net

To find the MAC address of a specific network interface, use the following command syntax:

cat /sys/class/net/interface_name/address

For example, to find the MAC address of a network interface, say ens33, the command would be:

cat /sys/class/net/ens33/address

How to find MAC address using GUI

Those who prefer a graphical interface for their daily tasks can find their MAC address graphically using the network manager that comes with their distribution. As in Ubuntu, you can use the network connection settings.

Open Settings on your Linux distribution by right-clicking on your desktop or application menu. In the left pane, click the Network tab. You will see all network interfaces connected to your system.

To find out the MAC address of a network interface, click the cog (settings) icon in front of it.

A new window will open with detailed information about your network interface. Here you will find the MAC address next to the Hardware Address label.

We've used GNOME for images in this tutorial, but other desktop environments will also have similar settings, just with different labels.

Find the MAC address of another system on the local network

Similar to your own MAC address, you can also find the MAC addresses of other systems on the local network. Here's how:

Using the arp Command

You can use ARP (Address Resolution Protocol) or Address Resolution Protocol to find out the MAC address for a given IP address. To find the MAC address of another system on the local network, ping its IP address with:

ping -c1

The ping command will use ARP to get the MAC address of the remote system. Once this information is received, it is stored in an ARP table, which you can view using:

arp -n | grep

This command will print the MAC address for the given IP address.

Using the arping utility

The arping utility helps you discover and test local systems on a network. It functions at the second layer of the OSI model and sends an ARP request to the system to determine if it is active and responding. It is different from the ping utility, which works at the third level.

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 the network by providing its IP address as an argument with the following command:

sudo arping -c 1

If you have multiple network adapters on your system, you can specify which interface the request should be sent from using the -I (capital "i") flag followed by the interface name:

sudo arping -c 1 -I interface_name

For example, the following command will send a single 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

As output, you will receive an ARP response from the target system containing its MAC address.

Easily Find Your MAC Address in Linux

Given the various methods for finding a MAC address in Linux, you can choose whichever is convenient for you.

Just like on Linux, you can also find the MAC address on Windows and macOS; however, they have different command sets and GUIs.

2544130cookie-checkHow to find MAC address in Linuxno

similar

Publication author

offline 1 hour

Comments: 6Publications: 1188Registration: 29-04-2020
Обзоры,Программы
#find #MAC #address #Linux