0800-31-0700 for new subscribers
0800-31-0800 technical support

How to find out and change the MAC address in Linux

Home /

Blog

/

How to find out and change the MAC address in Linux

How to find out and change the MAC address in Linux

02.03.2025

Internet

207

Previously, we told you about the MAC address and how to find it and change it in Windows. In this article, you will learn how to do it in different ways if you have Linux installed on your computer.

How to find the MAC address at the command line

Using the ip command

The ip command in Linux allows you to add or remove a network interface, assign or remove IP addresses, display the status of network interfaces, and perform other useful tasks. You can find out the MAC address of your system by using the following ip command:

 ip link show

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


The ip link show command will also help you find out the MAC address of a particular network interface.

Using the ifconfig command

The ifconfig command in Linux allows you to configure and display the status of network interfaces. It also makes it possible to activate and deactivate a network interface.

To find out the MAC addresses of all available network interfaces (even deactivated ones), use the ifconfig command with the -a parameter in this way:

 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 active network interfaces, use the ifconfig command without any parameters:
 ifconfig
In the raw data, you can find the MAC address of your interface as shown below:


Using the ethtool utility

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

Here is the command to do this:

 ethtool -P interface_name


How to get MAC address from /sys/class/net directory

The /sys/class/net directory contains information about the network devices connected to the system. This directory has a separate subdirectory for each network interface, for example, /sys/class/net/enp0s3 and /sys/class/net/ens37.

Each subdirectory contains a different file for each network attribute: MAC address, the operating state of the network device, its duplex, its MTU, etc. The MAC address information is stored in the address file.

To get a list of interfaces connected to your system, you can use this command:

 ls /sys/class/net


You can find the MAC address of a particular network interface by using the following command syntax:
 cat /sys/class/net/interface_name/address
For example, to find the MAC address of a network interface (such as enp0s3), the command would look like this:
 cat /sys/class/net/enp0s3/address

How to find the MAC address using the GUI

If you prefer a graphical interface, you can find your MAC address graphically using the network manager that comes with the distribution. To do this:

  1. Open "Settings" in your Linux distribution by right-clicking on the desktop or in the application menu.  
  2. In the left pane, click on the "Network" tab. You will see all the network interfaces connected to your system.
  3. To find out the MAC address of a network interface, click the "Cog" icon in front of it.


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


How to find the MAC address of another system on the local network

Similar to the procedure for finding your MAC address, you can also find the MAC addresses of other systems on the local network.

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 LAN, ping its IP address using the following command:

 ping -c1 <IP address>
The ping command will use ARP to obtain the MAC address of the remote system. The information obtained will be stored in an ARP table, which can be viewed using the command below:

 arp -n | grep <IP address>


Using the arping utility

The arping utility helps to detect and check local systems on the network. It functions similarly to the ping utility, but unlike the ping utility, it operates at layer 2 of the OSI model and uses the ARP protocol. 

You can install arping using the following commands:

  • in Debian-based distributions:
     sudo apt install arping
  • in RHEL-based distributions:
     sudo yum install arping

    After installation, find the MAC address of another system on the network by specifying its IP address using the following command:

 sudo arping -c 1 <IP address>

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

 sudo arping -c 1 -I interface_name <IP address>

For example, the following command will send a single ARP request from its enp0s3 interface to the IP address of the remote system 10.0.2.2.

 sudo arping -c 1 -I enp0s3 10.0.2.2

On output, you will receive an ARP response from the target system that contains its MAC address.


Now, knowing the different ways to find a MAC address in Linux, you can choose and use whichever one you like.

Comments

0

Еще комментарии