Here's a simple solution to getting your mac address to either randomize or use a custom address upon rebooting or making a new wireless connections in Kali Linux. I decided to post this after having an issue with macchanger which I couldn't find a working solution for in the forum.
After the latest system update, macchanger stoped working entirely. It would not change the MAC address for either wlan0 or eth0 and every attempt would return "[ERROR] Could not change MAC: interface up or insufficient permissions: Device or resource busy"
This would return the error message and would not allow the address to change. I tried several other recommended methods with no success and finally decided to try to just reinstall macchanger which ultimately fixed the error.# service NetworkManager stop
# ifconfig wlan0 down
# macchanger -r wlan0
# ifconfig wlan0 up
# service NetworkManager start
TO FIX THE ISSUE DO THE FOLLOWING:
Remove macchanger
This command will also force the removal of fern-wifi-cracker & kali-linux-full...# apt-get remove macchanger -y
So install them all again.
After the install is complete the error message is no more. Now to set up automatic MAC spoofing/randomization. This is the same method that I use in Fedora & Redhat.# apt-get install macchanger fern-wifi-cracker kali-linux-full -y
First create a new startup service:
Insert the following text into the new file:# nano /etc/systemd/system/[email protected]
Enable the new service and modify the interface name ('wlan0') to match your setup:[Unit]
Description=macchanger on %I
Wants=network-pre.target
Before=network-pre.target
After=sys-subsystem-net-devices-%i.device
[Service]
ExecStart=/usr/bin/macchanger -r %I
Type=oneshot
[Install]
WantedBy=multi-user.target
MACCHANGER WILL NOW RANDOMIZE YOUR MAC AT REBOOT# systemctl enable [email protected]e
IF YOU WISH TO HAVE MACCHANGER RANDOMIZE YOUR MAC WITH EACH NEW CONNECTION
DO THE FOLLOWING:
Enter the following text into the file be sure to modify 'wlan0' to match your interface name:# nano /etc/NetworkManager/dispatcher.d/random_mac.sh
Now make the file executable:#!/bin/sh
IF=$1
STATUS=$2
MACCHANGER=/usr/bin/macchanger
WLANIFACE="wlan0"
if [ -z "$IF" ]; then
echo "$0: called with no interface" 1>&2
exit 1;
fi
if [ ! -x $MACCHANGER ]; then
echo "$0: can’t call $MACCHANGER" 1>&2
exit 1;
fi
if [ "$IF" = "$WLANIFACE" ] && [ "$STATUS" = "down" ]; then
/usr/sbin/ip link set $IF down
$MACCHANGER -r $IF
/usr/sbin/ip link set $IF up
fi
OPTIONAL: Every time you disconnect and reconnect to the same access point the DHCP server will give you a fresh IP address from the table. If you are constantly disconnecting and reconnection this can fill the table and in effect crash some routers. If you would like to prevent this, you can use an univocal DHCP identifier for the wireless card, instead of its MAC address.# chmod +x /etc/NetworkManager/dispatcher.d/random_mac.sh
Create or edit the following file:
Edit or create the dhcp-client-identifier to any value you choose other than the default 'hardware':# nano /etc/dhcp/dhcpclient.conf
THATS IT. ENJOY YOUR NEW RANDOM MAC ADDRESS.send dhcp-client-identifier = "kali_wifi_card";