Find MAC Address of Default Gateway

6 lines
ip neigh show \
  | grep -P "$(ip -4 route | grep -Po "(?<=default via )(.+?)\s" | head -n 1)" \
  | grep -Po "([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}"
ip neigh show \
  | grep -P "$(ip -6 route | grep -Po "(?<=default via )(.+?)\s" | head -n 1)" \
  | grep -Po "([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}"