ARP spoofing detection/prevention seems to be quite popular here. With other techniques like port stealing aside, I'm wondering if the following could work to prevent it:
Whenever my Linux workstation gets network connection, I could auto-add a static ARP entry designated with the MAC address of the default gateway as obtained at that moment. (Supposedly, gateway NICs don't just change their MACs afterwards.)
Implemented as something to the like of the following script which can be put into /etc/network/if-{up,down}.d
on a Debian-based GNU/Linux (or in /etc/NetworkManager/dispatcher.d
wherever that is used):
#!/bin/sh
# If not Debian, account for NetworkManager's dispatcher.d
IFACE="${IFACE:-$1}" MODE="${MODE:-$2}"
# Support eth/wlan/wwan interfaces
case "$IFACE" in en*|eth*|wl*|ww*) ;; *) exit 0; esac
neighbors="/run/ifup.$(basename "$0").$IFACE"
case "$MODE" in
start|*up*)
sleep 6
arp -an -i "$IFACE" | cut -d' ' -f 2,4 | tr -d '()' > "$neighbors"
while read host hwaddr; do arp -s $host $hwaddr; done < "$neighbors"
;;
stop|*down*)
[ ! -f "$neighbors" ] && exit 0
while read host _hwaddr; do arp -d $host; done < "$neighbors"
rm "$neighbors"
;;
esac
I guess there is a race condition right after the connection is established, but other than that, to secure the MAC of the default gateway if nothing else, would something lightweight like this work and work well enough to set it and forget it? Would it get in the way of wifi roaming? Are there any other considerations?