How to Find the MAC Address on Raspberry Pi? (3 easy ways)


On some networks, you can configure a MAC address whitelist to only allow authorized devices.
You probably know how to do this on other systems (Windows for example), but you might need help finding it on Raspberry Pi.
You are at the right place :)! I will tell you everything you need to know about this topic.

The easiest way to find the MAC address on a Raspberry Pi is to use the command “ifconfig”. The MAC address just after the keyword “ether” in the section corresponding to your network interface. It’s represented as a 12-digit hexadecimal number (AA:BB:CC:DD:EE:FF).

In this tutorial, I’ll show you how to find it with ifconfig, as well as other ways to find it in different situations.

If you are really interested in improving your skills on Raspberry Pi, I highly recommend you check out my e-book here. It’s a 30-day challenge from beginner to master, with step-by-step tutorials and many projects to help you practice along the way.

Find the MAC Address on Raspbian

So, the first way to find your MAC address on Raspbian is to use ifconfig.
This command is available on any Raspbian version (Lite or Desktop).

On Raspbian Lite, you can use it once logged on.
On Raspbian Desktop, you need to open a terminal before you can use it.

Here is how to do this on Raspbian Desktop:

  • Open the terminal (shortcut in the top bar):
  • Type the ifconfig command and press enter.
  • The result look like this:
  • You can see one paragraph per network card on your system.
    eth0 corresponds to the wired card, and wlan0 is the Wi-Fi card.
    In each paragraph, you can see the IPv4 and IPv6 configuration, the MAC address and a few statistics about the network card.
  • The MAC address is visible after the “ether” keyword, here:
  • So, in this case, the MAC address is b8:27:eb:4f:15:95.

That’s it! You can now do the same thing on your Raspberry Pi, and use the MAC address in your router configuration.

A bit lost in the Linux command line? Check this article first, which will give you the most important ones to remember with a free cheat sheet you can download to have all of them at your fingertips.

Get the MAC Address in a network scan

If your goal isn’t to authorize a device to access your network, but to assign it a static IP address in the DHCP server, you can also scan the network to find an equipment connected on the network (including any Raspberry Pi).

To do this, I like to use Advanced IP Scanner on Windows:

  • Start by downloading it here: https://www.advanced-ip-scanner.com/.
  • Install it like any other application and then start it.
  • Enter the network range to scan.
    I think the software will detect it automatically.
  • And press the “Scan” button.
  • After a few seconds, you’ll get the full list of your network devices, like this:
  • And as you can see on the highlighted line, you can also get the Raspberry Pi MAC address this way!

Get the MAC Address in a script

The last scenario I can think of is if you need to get the MAC address in a script to use on many Linux systems, including some Raspberry Pi.
I will show you here two ways to do this: in Python and in a Shell script.

Python script

Python is a popular language on Raspberry Pi, and is also available on any operating system.
So, it’s a good idea to use it for your projects.

If you need to find the MAC address of a system in Python, there are several ways to do this.
I prefer to keep it simple by installing get-mac and use it directly in your code.
Here is how to do this:

  • If not yet installed, you need to install pip on your system:
    sudo apt install python-pip
  • Then install get-mac with the pip command:
    sudo pip install get-mac
    The project page is here if you need more information.
  • Once installed, you can use it in any Python script like this:
    from getmac import get_mac_address

    eth_mac = get_mac_address()
    print(eth_mac)
  • There are many options you can use. For example, to get the MAC address from a remote device or to specify if you want the eth0 or wlan0 address.
    All the information is on the project website.

If you prefer not to install anything on your system, you can use the uuid library.
The cleanest way I found to get it is like this:

import re,uuid

mac=':'.join(re.findall('..', '%012x' % uuid.getnode()))
print(mac)

uuid.getnode() returns the identifier, and you need to use join and findall to format it the correct way.

If you are new to Python programming, I highly recommend starting with this article, that will explain the basics. It’s not complicated, but you have to learn in the correct order before trying this 🙂

Raspberry Pi Bootcamp
Sale: 10% off today.
Take it to the next level.
I'm here to help you get started on Raspberry Pi.
Learn all the skills you need in the correct order.

Shell script

The last method I want to show you is in a shell script.
In a shell script, we generally use system commands.
As far as I know, there isn’t a command to directly get the MAC address, but you can read the /sys/class/net/<INTERFACE>/address file to read the MAC address currently used.

You can do something like that for example:

#!/bin/sh
 
if [ -e /sys/class/net/eth0 ]; then
      MAC=$(cat /sys/class/net/eth0/address)
else
      MAC=$(cat /sys/class/net/wlan0/address)
fi

echo $MAC

This script tries to read the file corresponding to eth0.
If it doesn’t exist, it reads the wlan0 file.

Conclusion

That’s it, you now know how to get the current address MAC on a Raspberry Pi.
You have seen the basic way (ifconfig), but also alternative methods to get it depending on your needs.
If you have any other case where you need to get it, feel free to leave a comment below, so I can try to help you.

As usual, thanks for sharing this post on your favorite social network if you find it useful :).

Raspberry Pi Resources

Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now

Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiples projects with step-by-step guides.
Download the e-book

VIP Community
If you just want to hang out with me and show your support, you can also join the Patreon community. I share behind-the-scenes content there and give you early access to my content. You’ll also get a shoutout when you join.
More details here

You can also find all my recommendations for tools and hardware on this page.


This tutorial doesn't work anymore? Report the issue here, so that I can update it!


Patrick Fromaget

I'm the lead author and owner of RaspberryTips.com. My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with a web developer experience.

Recent Posts

Raspberry Pi Bootcamp - 10% off