Here’s a shell script to figure out what the IP4 gateway MAC address is, and to set that as the IP6 gateway MAC:
#! /bin/bash
# Get the v4 gateway IP address
V4GW=$( ip route get 1 | sed 's/.* via //; s/ .*//; q' )
# Get the MAC address for that
V4MAC=$( ip neigh | grep -F -w "$V4GW" | sed 's/.* lladdr //; s/ .*//'; )
# Get the IPv6 gateway IPv6 address
V6GW=$( ip r g 1:: | sed 's/.* via //; s/ .*//; q' )
# Check if the IPv6 gateway is in IP6-Neighbour-Discovery failure
if ip n | grep -wF "$V6GW" | egrep -q 'INCOMPLETE|FAILED' ; then
# Get the ip neigh[bour] string, e.g. dev eth0 lladdr 00:01:02:00:ff:ee
NEIGHBOUR=$( ip neigh | grep -wF "$V6GW" | sed 's/ *\(INCOMPLETE\|FAILED\).*//' )
# delete the failed neighbour discovery
ip neigh del $NEIGHBOUR
# delete add a static neighbour
ip neigh add $NEIGHBOUR lladdr $V4MAC
fi
This was necessary for a machine where the gateway decided that responding to neighbour solicit requests was optional. (Still don’t know why it felt like that.)