Open In App

How to get the MAC Address – 10 Different Methods – Kali Linux

Last Updated : 25 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

MAC Address or Media Access Control Address is the unique address that is issued to our system by the network interface controller (NIC) for seamless communication at the DDL (Data Link Layer) of the Network Segment. This MAC address is also used as a network address for different network topologies. As this address is unique, it can be retrieved in different ways. In Windows System, the process of getting the MAC address is easy and simple, but in Linux systems, it is quite difficult to get the MAC address. In Linux Systems, the Ethernet device is mostly called “eth0“. And this contains our actual desired MAC address. In this article, we will explore 10 different methods through which we can retrieve our MAC address on the Kali Linux system. Using any of the methods, it will be easier to identify the unique MAC address of your system.

How to get the MAC Address?

Below we have listed all the 10 methods through which we can get our MAC address on Linux systems:

  • Method 1: Using ifconfig command
  • Method 2: By opening the /sys/class/net/eth0/address file
  • Method 3: Using the grep command with the regex expression
  • Method 4: Using ip command
  • Method 5: Using ip with the grep command
  • Method 6: Using ifconfig with the grep command
  • Method 7: Using the LANG variable
  • Method 8: Using ethtool utility
  • Method 9: Using Python Script
  • Method 10: Using the dmesg command

So, let’s see all the methods one by one with the proper command execution and output screenshots:

Method 1: Using ifconfig command

In this method, we will be using the inbuilt ifconfig command to get the MAC address of our system. This command is used for configuring the kernel network interfaces. To view the MAC address of our system, we need to execute the below-stated command in the terminal.

ifconfig | grep ether
Using ifconfig command

Using ifconfig command

In the above screenshot, you can see that the address that follows the “ether” is our actual desired MAC address.

Method 2: By opening the /sys/class/net/eth0/address file

Step 1: In this method, we will print the MAC address by accessing the current interface file which is stored in the directory of /sys/class/net/eth0/address. We can use any of the editors, or command line utility (cat) to view the contents of this file and get the MAC address.

cat /sys/class/net/eth0/address
Printing current interface address

Printing current interface address

Step 2: As the above command gives only the current interface address, if we need to get the address of all the interfaces then we can use the below command in the terminal.

cat /sys/class/net/*/address
Printing all interface address

Printing all interface address

Method 3: Using the grep command with the regex expression

In this method, we will be using the grep command along with the custom regex expression which will work for us to get the MAC address of our system. So run the below command in the terminal to get the MAC address.

ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
Using grep with regex expression

Using grep with regex expression

Method 4: Using ip command

Step 1: In this method, we will use the inbuilt IP link command to see the MAC address of our eth0 interface. We can also see the address of any interface, just by giving the interface name as an input. Run the below command to get the MAC address.

ip link show eth0
Using IP command

Using IP command

Step 2: Here, we will display the MAC address using the more verbose format. We can use the awk command to display only the address rather than other stuff.

 ip link show eth0 | awk '/ether/ {print $2}'
Only MAC address output

Only MAC address output

Method 5: Using ip with the grep command

In this method, we will use the combination of the ip and grep commands to get the MAC address along with more configuration information about the interface. So run the below command to get the address along with the information.

ip addr | grep -C1 "link/ether"
Using IP with grep command

Using IP with grep command

Method 6: Using ifconfig with the grep command

In this command, we will use the ifconfig along with the grep command to get the MAC address of our Kali Linux system. So run the below command in the terminal to get the MAC address.

ifconfig eth0 | grep -Eo ..\(\:..\){5}
Using ifconfig with grep command

Using ifconfig with grep command

Method 7: Using the LANG variable

In this method, we will use the LANFG variable to display the MAC address. So run the below command to get the MAC address by displaying the variable.

LANG=C ip link show | awk ‘/link\/ether/ {print $2}’
Using Variable

Using Variable

Method 8: Using ethtool utility

In this method, we get the MAC address of our system by using the tool name “ethtool“. This tool is already present in our Kali Linux system. We just need to run the below command and get the MAC address.

ethtool -P eth0 | awk ‘{print $NF}’
Using ethtool utlity

Using ethtool utlity

Method 9: Using Python Script

Step 1: In this method, we will be writing our own Python script and getting the MAC address. So using any of the editors, write the below Python script. Save the file with the (.py) extension.

Python3




import os
 
sys_net = '/sys/class/net'
for dev in os.listdir(sys_net):
    with open(os.path.join(os.path.join(sys_net, dev), 'address')) as f:
        print(dev, f.read(), end='')


Step 2: Now, by using the Python command run the script and get the MAC address on your terminal printed in just one click.

python3 mac.py
Using Python script

Using Python script

Method 10: Using the dmesg command

In this method, we will be using the open-source utility named dmesg to get the MAC address of our system. So run the below command in the terminal to get the MAC address.

dmesg | grep eth
Using dmesg command

Using dmesg command

Conclusion

In conclusion, the process of getting the MAC address of our system is easy in a Windows environment, but it’s quite tricky in Linux OS, as compared to other environments, many methods can help us to get the MAC address of our Kali Linux system easily. As in this article, we have seen 10 different methods, using any of the above methods, we can get our MAC address printed in the terminal in just a single click.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads