Skip to content

sanesecurityguy/freebsd-random-wifi-mac-address

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

FreeBSD Random Wi-Fi MAC Address

A simple method of randomizing your Wi-Fi MAC address everytime you turn Wi-Fi on.
Works on FreeBSD 15.0.

Instructions

  1. Create /etc/rc.conf.d/MAC-Prefixes.txt containing the list of MAC address prefixes you want to use. The list can contain any valid MAC address prefixes, but a sample file is provided in this repo containing some randomly selected prefixes from common mobile device manufacturers.
  2. Copy /etc/start_if.wlan0 to your system. The part that creates the second half of the random MAC address comes from Vermaden's network.sh script here, so he is to thank for that.
  3. Add the line create_args_wlan0="wlanaddr $(cat /etc/rc.conf.d/Random-MAC-Address.txt)" to your /etc/rc.conf file. A sample file is also provided in this repo containing only the minimum configuration lines related to Wi-Fi.
  4. Create an initial /etc/rc.conf.d/Random-MAC-Address.txt file containing any valid MAC address. This is necessary because, unexpectedly, /etc/start_if.wlan0 runs after the wlan0 interface is created, not before, so the first time you create wlan0 with this configuration will fail. Another sample file is provided in this repo.
  5. (Bonus) Also want to stop sending your hostname to the router during DHCP requests but haven't figured out how yet? Add send host-name ""; to /etc/dhclient.conf.
  6. Recreate the wlan0 interface by running service netif restart wlan0.

Note 1

As previously mentioned, /etc/start_if.wlan0 unexpectedly runs after the wlan0 interface is created, so whatever MAC address you see in /etc/rc.conf.d/Random-MAC-Address.txt will be your next MAC address, not your current MAC address.

Note 2

This method makes use of an intermediate file (/etc/rc.conf.d/Random-MAC-Address.txt) that contains the random MAC address before it gets used by ifconfig. The reason why we do not simply add something like:

create_args_wlan0="wlanaddr $(sort -R /etc/rc.conf.d/MAC-Prefixes.txt | head -n 1):$(env LC_ALL=C tr -c -d '0-9a-f' < /dev/random | head -c 6 | sed -e 's|\(..\)|\1:|g' -e 's|:$||')"

...to /etc/rc.conf is because, while that will work when you're already logged in to userspace, it will cause startup to hang at cuse when you reboot.

There may be a slightly more elegant way to achieve this by passing a $RANDOM_MAC_ADDRESS variable directly to netif. I attempted this using various means but ran into the following problems:

  • Exporting the variable directly from /etc/start_if.wlan0: This does not work because that script runs after wlan0 is created, so the variable is still empty when wlan0 is created.
  • Adding a netif_env to /etc/rc.conf: The variable remains empty when creating wlan0.
  • Creating a /etc/rc.conf.d/netif file containing the variable: Still empty when creating wlan0.
  • Potentially other methods that I have forgotten.

So having an intermediate file store the MAC address is the most elegant solution I could make work. On the plus side, since that file stores your next MAC address, it allows you to temporarily set whatever MAC address you choose when you need to, and then go back to a random one without having to remember to reconfigure it.

About

A simple method of randomizing your Wi-Fi MAC address everytime you turn Wi-Fi on.

Topics

Resources

License

Stars

Watchers

Forks