LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   Automatically change network interface's mac address at boot (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/automatically-change-network-interfaces-mac-address-at-boot-4175716898/)

starkid 09-18-2022 08:59 PM

Automatically change network interface's mac address at boot
 
This is for presenting a false mac address (the ID of a wired or wireless network card). You might do this to preserve your anonymity online (some public networks track mac addresses).

Make sure some version of cron (I did this with cronie) and macchanger are installed. At the command line, verify the install location of macchanger (aka its full path) with the whereis command (I had to use sudo to find the location):

Code:

sudo whereis macchanger
Get the name of the network interface you want to change:

Code:

ip link show
This shows all the network devices installed in the computer; if you haven't changed the names, the wireless interface names probably start with 'w' and the wired ones probably start with 'e.' The output will look similar to this:

Code:

1: lo: text-you-can-ignore
2: wlan0 text-you-can-ignore
3: wlan1 etc.
4: enp10s0 etc. etc.

The wlan0, wlan1, and enp10s0 are the interface names (the computer has two wireless cards and one Ethernet card in this example).

Create a cron job with sudo aka for the root account (because macchanger must be run with root privileges):

Code:

sudo crontab -e
A file should pop up in your preferred text editor (you can set a preferred editor with the EDITOR environment variable; look it up).

In the file, type:

Code:

@reboot /full/path/to/macchanger -options interface_name
For example
Code:

@reboot /sbin/macchanger -r eth0
gives the network device eth0 a random mac address every time you boot the computer.

Save and close the file.

Check cron man page for running the job at other times/intervals and check macchanger man page for other options.

Optional: If your system has no cron log file and you want to check errors/output of this cron job, create a log file at the same time you create the cron job (or edit the existing cron job by typing
Code:

sudo crontab -e
again:

Code:

@reboot /path/to/macchanger -options interface_name >> /full/path/to/some_textfile > 2>&1
Cron will create some_textfile if it doesn't exist.


All times are GMT -5. The time now is 07:28 PM.