I wanted to change the mac address on the Raspberry Pi. After a bit of googling, I was able to change the mac address using ip link however when the device is rebooted, the changes are reverted. It appears there isn’t an easy way to change the mac address permanently so I decided to create a script to apply the changes on start up.

Fortunately, the LineageOS raspberry build already came with support for running start up scripts from /system/etc/init.d/. This means I just needed to add script in there.

Here are steps I took:

  1. Enable the developer options and enable the shell emulator.

  2. Remount the file system with write permission if it doesn’t have it already.

mount -oremount,rw /system
  1. Create a script in /system/etc/init.d/.
touch /system/etc/init.d/99macaddrchange
  1. Add the following content to the script.
#!/bin/sh
set -ex

# If "eth0" is the network adapter we want to change.
ip link set dev eth0 down
ip link set dev eth0 macaddr xx:xx:xx:xx:xx:xx
ip link set dev eth0 up
  1. Reboot the Raspberry Pi and run ip link show again to check if the changes are automatically applied.

References: