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
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
So, the first way to find your MAC address on Raspbian is to use
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
ifconfigcommand 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.
Are you a bit lost in the Linux command line? Check this article first, for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands 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 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()
- 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:
mac=':'.join(re.findall('..', '%012x' % uuid.getnode()))
uuid.getnode() returns the identifier, and you need to use
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 🙂
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.
Sale: 10% off today.
Get the eBook.
Do more with your Raspberry Pi, learn the useful concepts and take the shortcuts.
You miss half of the fun of using a Raspberry Pi if you don’t know anything about Python.
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.
Support me: Join the community on Patreon to show your support, get behind-the-scenes content and other awesome perks!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!
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 multiple projects with step-by-step guides.
Download the e-book.
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.
Need help building something with Python?
Create, understand and improve any Python script for your Raspberry Pi.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.
You can also find all my recommendations for tools and hardware on this page.