Changing MAC Addresses
Changing MAC Addresses
Raspberry Pi Single-Board
Computers
Raspberry Pi Ltd
Colophon
© 2020-2023 Raspberry Pi Ltd (formerly Raspberry Pi (Trading) Ltd.)
This documentation is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND)
licence.
build-date: 2023-12-11
build-version: githash: 55da6e9-clean
RPL reserves the right to make any enhancements, improvements, corrections or any other modifications to the
RESOURCES or any products described in them at any time and without further notice.
The RESOURCES are intended for skilled users with suitable levels of design knowledge. Users are solely responsible for
their selection and use of the RESOURCES and any application of the products described in them. User agrees to
indemnify and hold RPL harmless against all liabilities, costs, damages or other losses arising out of their use of the
RESOURCES.
RPL grants users permission to use the RESOURCES solely in conjunction with the Raspberry Pi products. All other use of
the RESOURCES is prohibited. No licence is granted to any other RPL or other third party intellectual property right.
HIGH RISK ACTIVITIES. Raspberry Pi products are not designed, manufactured or intended for use in hazardous
environments requiring fail safe performance, such as in the operation of nuclear facilities, aircraft navigation or
communication systems, air traffic control, weapons systems or safety-critical applications (including life support
systems and other medical devices), in which the failure of the products could lead directly to death, personal injury or
severe physical or environmental damage (“High Risk Activities”). RPL specifically disclaims any express or implied
warranty of fitness for High Risk Activities and accepts no liability for use or inclusions of Raspberry Pi products in High
Risk Activities.
Raspberry Pi products are provided subject to RPL’s Standard Terms. RPL’s provision of the RESOURCES does not
expand or otherwise modify RPL’s Standard Terms including but not limited to the disclaimers and warranties expressed
in them.
1.4 2 November 2022 Update the OUI list, and provide a link
to IEEE OUI database
Scope of document
This document applies to the following Raspberry Pi products:
* * * * * * * * * * * * * * * * * *
Introduction
This white paper describes how to set a specific media access control (MAC) address on your Raspberry Pi device. It
applies to Ethernet, wireless, and Bluetooth interfaces.
Three mechanisms are described: one for devices up to Raspberry Pi 3, one for Raspberry Pi 4/400 and Compute Module
4, and one for Raspberry Pi 5.
This whitepaper assumes that the Raspberry Pi is running the Raspberry Pi operating system (OS), and is fully up to date
with the latest firmware and kernels.
Introduction 3
Changing the MAC Address on Raspberry Pi Single-Board Computers
Techniques
$ ip link
The MAC address is the set of six hexadecimal numbers in the form aa:bb:cc:dd:ee:ff.
On devices prior to Raspberry Pi 4 and 400, the MAC address is generated from the Raspberry Pi board’s serial number.
For example, if your Raspberry Pi serial number is 58d2ec5c, the MAC address will be generated from the bottom six
nibbles, combined with the Raspberry Pi Foundation Organizationally Unique Identifier (OUI), which is b8:27:eb, so the final
MAC address would be b8:27:eb:d2:ec:5c.
This address is generated on startup by the firmware, and passed on to the Linux kernel for use by the Ethernet driver.
On Raspberry Pi 4 and 400 with the 2711 SoC, the MAC address is generated by combining a Raspberry Pi Ltd OUI
(dc:a6:32 or e4:5f:01) with a final three bytes that are generated at production time from a sequential set; for example,
dc:a6:32:c4:7c:5f.
This MAC address is stored in the one-time programmable (OTP) memory of the SoC and cannot be permanently
changed, but can be overridden in software as described in a later section.
Raspberry Pi MAC addresses are currently allocated from five OUI ranges, although new ranges will be added as each
existing one is used up. Each range provides 0xffffff (six nibbles, 16777216 decimal) different IDs.
OUI Owner
For an up-to-date list of all Raspberry Pi Ltd OUIs, please see the IEEE website at https://regauth.standards.ieee.org/
standards-ra-web/pub/view.html#registries.
You can temporarily change the MAC address of the Ethernet adapter with the ip command:
The same process also applies to the wireless networking MAC address:
NOTE
These commands are not persistent over a reboot, so they will need to be re-entered each time or added to a login
script to make this automatic.
Programming the OTP requires using the SET_MAC_ADDRESS_OTP mailbox call (ID: 0x00030051). A utility is provided on all
Raspberry Pi OS installations for making mailbox calls to the firmware. The mailbox system accepts data in 32-bit words
in little-endian format, so to set a MAC address of aa:bb:cc:dd:ee:ff you will need to do the following:
The two '6' parameters are the length, in bytes, of the question and response buffers.
Note that this operation is irreversible: once an OTP bit has moved from 0 to 1 it can never be set back to 0, so please be
careful when using this command.
Setting a persistent alternative MAC address on devices using the 2711 SoC
(Raspberry Pi 4 and 400, CM4)
On the 2711 SoC, a Raspberry Pi OUI-based MAC address is already stored in the OTP memory during production, and this
particular entry cannot be changed. However, there are two options to override the preprogrammed MAC address, now
available in all boot modes.
The boot EEPROM configuration on these devices has a setting to update the MAC address:
MAC_ADDRESS=aa:bb:cc:dd:ee:ff
Setting a persistent alternative MAC address on devices using SoCs prior to 2711 (Raspberry Pi 1–3) 5
Changing the MAC Address on Raspberry Pi Single-Board Computers
Add the required MAC_ADDRESS, save, and reboot. The device should now use that MAC address when booting.
In bootloader firmware dated November 2022 onwards, there is a feature to allow the use of a MAC address programmed
into the customer OTP. By adding an OTP entry and then setting a bootloader flag, the bootloader will override the
Raspberry Pi MAC address from the OTP with the customer-specific version. The advantage of this over the previous
mechanism is that the OTP cannot be reprogrammed to change the MAC address and only one EEPROM configuration
image is necessary.
A MAC address requires two rows of customer OTP. The Customer OTP rows are OTP registers 36 to 43 in the vcgencmd
otp_dump output; a document available in the Raspberry Pi Ltd Product Information Portal covers using the OTP.
The rows that the bootloader uses for the MAC address are specified by the bootloader flag MAC_ADDRESS_OTP. For
example, to set to rows 0 and 1:
MAC_ADDRESS_OTP=0,1
The first value (row 0 in the example) contains the OUI and the most significant eight bits of the MAC address. The
second value (row 1 in the example) stores the remaining 16 bits of the MAC address. This is the same as the format
used for the Raspberry Pi MAC address programmed at manufacture.
Setting a persistent alternative MAC address on devices using the 2712 SoC
(Raspberry Pi 5)
The scheme used on Raspberry Pi 5 is an improvement on that used on Raspberry Pi 4. It allows you to set the MAC
addresses of the Ethernet, wireless, and Bluetooth systems, which is possible as the BCM2712 SoC has an enlarged OTP
area to store this extra information. The mechanism for programming in these values is similar to that on Raspberry Pi 3,
and uses the vcmailbox system.
In the following sections, the MAC address to set is defined as follows; replace 'x' in the examples provided with '2', '3', or
'4' according to the system for which you wish to set the MAC address:
x Device
2 Ethernet
3 Wireless
4 Bluetooth
$ vcmailbox 0x0003008x 6 6 0 0
Setting a persistent alternative MAC address on devices using the 2712 SoC (Raspberry Pi 5) 6
Changing the MAC Address on Raspberry Pi Single-Board Computers
$ vcmailbox 0x00030083 6 6 0 0
0x00000020 0x80000000 0x00030083 0x00000006 0x80000006 0xddccbbaa 0x0000ffee
0x00000000
The MAC address must be sent as two 32-bit words with the bytes in the right order. You can then set the customer MAC
with the following command:
If a customer MAC address is set to ff:ff:ff:ff:ff:ff in the OTP, then it is ignored. This means that if a mistake is made when
setting the OTP, you can set this value and the device will revert to the factory-set MAC address. Due to the write-once
nature of the OTP, you would no longer be able to set a customer MAC address on the device.
A multicast address is NOT considered valid. The least significant bit in the most significant octet of a MAC address is the
multicast bit, so make sure this is NOT set.
In the vast majority of cases, each device will require a unique MAC address to be assigned, so an image with a
predefined MAC address is inappropriate. There is therefore a need for schemes to provide a unique address after an
image has been installed. Raspberry Pi 4 devices are assigned unique MAC addresses during production, but these
include a Raspberry Pi Ltd OUI.
One possible algorithm that should give almost non-repeating numbers could be to take the entire MAC address and
replace the Raspberry Pi Ltd OUI segment (the first three bytes) with a manufacturer-specific OUI, leaving the last three
bytes as programmed. However, because of the large number of Raspberry Pi 4 devices that have been made, there are
multiple OUI ranges, so simply replacing the last three bytes could result in duplicate values. One option here is to use
multiple customer OUI ranges to replace the multiple OUI ranges allocated to Raspberry Pi Ltd.
An alternative scheme could be to use an external system to generate unique MAC addresses. The programmed image
could be designed, on the first boot, to read from a MAC address provider via a script, which subsequently sets up the
system to use the provided MAC address. The initial boot could be part of a provisioning/testing process on the
production line; a server could provide unique numbers on request, and connect to a backend database for further
provisioning information.
Possible schemes for programming the MAC address on a Raspberry Pi 4 or 5 device during production 7