Hi there,
as the world devolops as in “1984”, it may be a good idea to spoof your MAC adress. Here is how:
first we need to know the interfaces: ip link show
There may be an ethernet like enp0s25 as well as a WiFi interface like wlp3s0. After installing macchanger pacman -S macchanger
shut down your interfaces, to check if it worked without rebooting: ip link set wlp3s0 down && ip link set enp0s25 down
Then, create a service: touch /etc/systemd/system/macspoof@.service
Edit / copypaste the file as follows:
[Unit]
Description=macchanger on %I
Wants=network-pre.target
Before=network-pre.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
Enable the service for your interfaces immediatly and with every reboot systemctl enable --now macspoof@enp0s25.service && systemctl enable --now macspoof@wlp3s0.service
Bring up your interfaces ip link set enp0s25 up && ip link set wlp3s0 up
and see if MAC changed with ip link show
Voila!
You may want to have a script to cange mac without rebooting:
#! /usr/bin/env sh
ip link set enp0s25 down
ip link set wlp3s0 down
systemctl restart macspoof@enp0s25.service
systemctl restart macspoof@wlp3s0.service
ip link set enp0s25 up
ip link set wlp3s0 up
exit 0
Glad you like it. But even easyer to have a script doing all the steps, once run. Here you go:
#! /usr/bin/env sh
if [ "$EUID" -ne 0 ]
then
echo "Please run as root! Exit."
exit 1
fi
# Checking for macchanger
echo "This script will assign a random MAC adress for each interface immediatly and on every reboot."
echo "Checking for macchanger..."
macchanger &> /dev/null
if [ $? == 0 ]
then
echo "success!"
elif [ $? != 0 ]
then
read -p "Negative. Install it? (y) to continue " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
pacman -S macchanger
#UNDO01="pacman -Rs macchanger"
else
echo "Exit"
exit 1
fi
fi
# Write service file
echo "Creating service: /etc/systemd/system/macspoof@.service"
cat > /etc/systemd/system/macspoof@.service << EOF
[Unit]
Description=macchanger on %I
Wants=network-pre.target
Before=network-pre.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
ExecStart=/usr/bin/macchanger -r %I
Type=oneshot
[Install]
WantedBy=multi-user.target
EOF
#UNDO02="rm /etc/systemd/system/macspoof@.service"
# Determine interfaces and start service
echo "Start service for each interface..."
INTERFACES="$(awk '{print $1}' /proc/net/dev|grep :|sed "s/:.*//g")"
for INTERFACE in $INTERFACES; do
if [ $INTERFACE != "lo" ]
then
echo "Interface: "$INTERFACE"..."
ip link set $INTERFACE down
systemctl enable --now macspoof@$INTERFACE.service
ip link set $INTERFACE up
fi
done
#creating command changemacs
cat > /usr/bin/changemacs << EOF
#! /usr/bin/env sh
if [ "\$EUID" -ne 0 ]
then
echo "Please run as root! Exit."
exit 1
fi
INTERFACES="\$(awk '{print \$1}' /proc/net/dev|grep :|sed "s/:.*//g")"
for INTERFACE in \$INTERFACES; do
if [ \$INTERFACE != "lo" ]
then
ip link set \$INTERFACE down
systemctl enable --now macspoof@\$INTERFACE.service
ip link set \$INTERFACE up
fi
done
exit 0
EOF
chmod +x /usr/bin/changemacs
echo "Run 'changemacs' to assign random MAC adresses for each interface immediately."
It may be better to use pacman -Syu macchanger to ensure all of the libraries match. See this post for an example of a package failure after using pacman -S alone.
However, some prefer to backup before full system upgrades (in case of b0rkage) so this is far from clear-cut.
Also:
The grep & sed can be dropped and the search & filter added to awk instead: