Randomizing (spoofing) MAC address in Fedora 17
June 15th, 2012 by adminIn a previous post, I showed how to spoof mac addresses on bootup in Fedora 16. When I upgraded to Fedora 17, it stopped working. So, here’s how I got it to work in Fedora 17.
UPDATE: This stopped working in the recent kernel upgrade (I’m now at 3.5.2-1.fc17.x86_64) The fix is easy and I’ve updated the article.
Note: If you don’t want to do it on startup, but just want to change your MAC address (or want to put a script in cron to do it periodically) once you install macchanger, it’s pretty straightforward. The process is:
1) Use Apper to download and install “macchanger” or do “yum install macchanger”
2) do the following commands:
% service NetworkManager stop
% macchanger -a wlan0
(note, your interface may be something different than wlan0)
% service NetworkManager start
Of course, if you don’t want to use macchanger, you can do it directly by replacing that line with
ifconfig wlan0 hw ether aa:bb:cc:dd:ee:ff (with aa-ff replaced by whatever numbers you want)
Note that I don’t start and stop network (eg. service network stop, service network start). NetworkManager seems to take care of that for me. Now I can put it in a script, say, called changemac.sh
*************************
#!/bin/sh
service NetworkManager stop
macchanger -a wlan0
service NetworkManager start
********************
and put that in a bin directory (which I created) in my root’s home directory.
So, if you wanted to re-spoof your MAC every six hours, you could add this line to your root’s crontab:
0 */6 * * * /root/bin/changemac.sh
Though, of course, that might play havoc with any longstanding connections or downloads you might be doing.
/************
UPDATE: As someone pointed out, this assumes you are using NetworkManager. If you aren’t then do the same thing, only turning network on and off. If you know how to turn off NetworkManager, then you know how to do that…
*********/
But, if you want to do it at boot up, it’s a bit more complicated;
The first part of the solution is:
1) Use Apper to download and install “macchanger”, or do “yum install macchanger”
2) Put a script in /etc/init.d to run macchanger at startup. I created the file /etc/init.d/macchangerd that contained:
***************************************************
[root@localhost system]# more /etc/init.d/macchangerd
#!/bin/bash
#
#
start() {
echo “in macchangerd”
macchanger -a wlan0
}
# See how we were called.
case “$1″ in
start)
start
;;
*)
echo $”Usage: $prog {start}”
exit 1
********************************************
The issue seems to be this. If you want to change the MAC address *and* use NetworkManager (which I do), then you have to change the address *before* NetworkManager takes control. In Fedora 16, you could add a script to init.d and point to it early in the list of services to start in /etc/rc3.d.
In Fedora 17, it seems that the stuff in /etc/systemd runs the show, and NetworkManager kept starting before anything I put in /etc/rc3.d — even if I make it an S01 level command. So, in order to fix this, you have to play around with the services in the /usr/lib/systemd/system directory. If you want to review what’s going on there, take a look at this site. and the follow-up here.
I’m no expert on systemd, and I’m sure there’s a better way to do this, but if you look at the NetworkManager.service file in /usr/lib/systemd/system, it says:
************************************************
[root@localhost system]# more NetworkManager.service
[Unit]
Description=Network Manager
After=syslog.target
Wants=network.target
Before=network.target
[Service]
Type=dbus
BusName=org.freedesktop.NetworkManager
ExecStart=/usr/sbin/NetworkManager –no-daemon
# Suppress stderr to eliminate duplicated messages in syslog. NM calls openlog()
# with LOG_PERROR when run in foreground. But systemd redirects stderr to
# syslog by default, which results in logging each message twice.
StandardError=null
[Install]
WantedBy=multi-user.target
Alias=dbus-org.freedesktop.NetworkManager.service
************************************
What I get from that is that NetworkManager starts after syslog and before the network. What I want, is to take that macchanger script I did for Fedora 16, and get it going before NetworkManager..
So… I added a “macchanger.service” script in /usr/lib/systemd/system that tells it to run the script in init.d and start before NetworkManager:
****************************************************
[root@localhost system]# more macchanger.service
[Unit]
Description=macchanger
After=syslog.target
Before=NetworkManager.service
[Service]
Type=oneshot
ExecStart=/etc/init.d/macchangerd start
[Install]
WantedBy=multi-user.target
**********************************
This seems to do the trick. Let me know if it works for you…
UPDATE: This stopped working in a recent kernel/systemd upgrade. In order to make it work, I had to add one more step. I had to soft link the macchanger.system file to /etc/systemd/system/multi-user.target.wants. I.e:
ln -s /etc/systemd/system/multi-user.target.wants/macchanger.service /usr/lib/systemd/system/macchanger.service
Posted in Computer stuff | 4 Comments »
June 15th, 2012 at 4:39 pm
I have no idea what you just did, but it looks thorough and I’m sure someone will benefit.
June 18th, 2012 at 11:40 am
Heh. Trust me, there are people who care about this kind of thing…
Thanks for reading, though.
July 28th, 2012 at 3:32 pm
Is there a way to do this without writing a daemon. Just with ExecStart? Been trying to get this to work for a while. Also, how would I do this from /etc/ instead of /usr/lib/ so it doesn’t get overwritten. Thanks.
August 22nd, 2012 at 4:16 pm
The way you use /etc is to link to the /usr/lib file in /etc/systemd as noted in the last line of the updated article.
If you just want to use /etc/init.d, I guess you would put the script that turns off network manager, changes mac address, and turns network manger back on that I put in the first part of the article. Only you would put it in as a script for /etc/init.d. Then, I guess, you’d do it like I wrote for Fedora 16. I haven’t tried it, though.