5 Ways You Can Find Your MAC Address in Ubuntu

Every network interface has its own unique MAC address. Unlike IP addresses, which can change frequently and easily, MAC addresses are permanently tied to the hardware.

In this article, you will learn how to obtain the MAC address on a Ubuntu Linux system via many ways:

  1. With ip command
  2. With ifconfig command
  3. With address file
  4. With getmac.sh file
  5. With GUI

1. With ip command

Start by opening a terminal and using the following ip command to view information for all installed network interfaces.

Command: ip a

In below screenshot, we have highlighted our MAC address for the ens33 interface.

Get Mac Address Ways Ubuntu Linux Techhyme

With the help of some regular expressions, you can also find the MAC address

Command: ip a | grep ether | cut -d ” ” -f6

Get Mac Address Ways Ubuntu Linux Techhyme

Alternatively, you can also try the below command:

Command: ip link show ens33 | grep link/ether | awk ‘{print $2}’

Get Mac Address Ways Ubuntu Linux Techhyme

Command: ip a | grep link/ether | awk -F ” ” ‘{print $2}’

Get Mac Address Ways Ubuntu Linux Techhyme

2. With ifconfig command

ifconfig in short “interface configuration” utility for system/network administration in Unix/Linux OS to configure, manage and query network interface parameters via command-line interface or in a system configuration scripts.

The “ifconfig” command with no arguments will display all the active interfaces details such as IP Address, MAC Address, Interface Name, Netmask Address etc.

Command: ifconfig

Get Mac Address Ways Ubuntu Linux Techhyme

The below command also gives you the exact information (MAC address) of your ens33 interface:

Command: ifconfig ens33 | grep -o -E ‘([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}’

Get Mac Address Ways Ubuntu Linux Techhyme

Or in simple way, you can also use the following command:

Command: ifconfig | grep ether | cut -d ” ” -f 10

Get Mac Address Ways Ubuntu Linux Techhyme

Command: ifconfig | grep “ether*” | tr -d ‘ ‘ | tr -d ‘\t’ | cut -c 6-22

Get Mac Address Ways Ubuntu Linux Techhyme

3. With address file

If you just need to pull MAC addresses for a system and pair to an interface, you can easily get it done via below Bash command.

Command: cat /sys/class/net/*/address

Get Mac Address Ways Ubuntu Linux Techhyme

In case, if you want to get the details of particular interface, then you can replace the * with your interface name:

Command: cat /sys/class/net/ens33/address

Get Mac Address Ways Ubuntu Linux Techhyme

You can also use the following command:

Command: cat /sys/class/net/*/uevent /sys/class/net/*/address | grep -v IFINDEX | column | sed ‘s/INTERFACE=//’

4. With getmac.sh file

The below getmac.sh bash file can also be used to find the MAC address of any network adapter. To be able to do this, you will need the following piece of code:

#!/bin/bash
# Powered by Techhyme.com
D='/sys/class/net'
for nic in $( ls $D )
do 
      echo $nic
      if grep -q up $D/$nic/operstate
      then
           echo -n '     '
           cat $D/$nic/address
      fi
done

Get Mac Address Ways Ubuntu Linux Techhyme

Change the permissions of getmac.sh file and execute the file by typing the following command:

Command: ./getmac.sh

Get Mac Address Ways Ubuntu Linux Techhyme

5. With GUI

The following instructions will vary depending on which desktop environment you are using. However, all desktop environments will provide a way for the user to obtain their MAC address.

In the following screenshots, we are using the GNOME desktop environment of Ubuntu.

Open up your system’s network settings menu. On GNOME, you can access it by clicking the upper right corner and clicking on Wired/Wi-Fi Settings.

Open the settings panel for the network interface that you wish to obtain the MAC address of. In the case of GNOME, that is done by clicking on the corresponding cog wheel as shown in below screenshot.

Get Mac Address Ways Ubuntu Linux Techhyme

Our MAC address can now be seen under the label of Hardware Address as highlighted in below screenshot.

Get Mac Address Ways Ubuntu Linux Techhyme

We recommend using the command line method, as it is universal across all Linux systems and should work regardless of which Linux distribution you are on.

You can also read:

Leave a Reply