Commit 56077c18 authored by Felix Eckhofer's avatar Felix Eckhofer 🤹🏼
Browse files

Add randomize-mac

parent 5a8da855
# temporarily shut down an interface and randomize the mac,
# requires the macchanger tool.
# place in /etc/network/if-post-down.d to renew the mac everytime
# a network interface is brought down (recent versions of
# NetworkManager no longer support if-pre-up.d)
PRESTATE="`ip addr show dev \"$IFACE\" up 2>>\"$LOGFILE\"`"
date >> "$LOGFILE"
echo "Running randomize-mac for interface '$IFACE'" >> "$LOGFILE"
echo >> "$LOGFILE"
[ -n "$PRESTATE" ] && ip link set dev "$IFACE" down >>"$LOGFILE" 2>&1
macchanger -A "$IFACE" >>"$LOGFILE" 2>&1 || FAILED=1
[ -n "$PRESTATE" ] && ip link set dev "$IFACE" up >>"$LOGFILE" 2>&1
if [ "$FAILED" = "1" ]; then
cat "$LOGFILE" | mail -s "[`hostname`] macchanger failed" root
rm -f "$LOGFILE"
# upstart script to run randomize-mac for a list of interfaces
# place in /etc/init
description "Randomize MAC address on boot"
start on starting network-manager
pre-start script
export IFACE
for IFACE in eth0 wlan1; do
end script
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment