Skip to content

Instantly share code, notes, and snippets.

@sjtosco
Last active March 20, 2024 13:40
Show Gist options
  • Save sjtosco/01f2fa5461ce65f936ca4d40c1c6caa8 to your computer and use it in GitHub Desktop.
Save sjtosco/01f2fa5461ce65f936ca4d40c1c6caa8 to your computer and use it in GitHub Desktop.
Check router (gateway) of specific interface
get_gw_by_iface(){
# Return router ip of interface
# Usage: get_gw_by_iface IFACE
sudo traceroute -n -i $1 -m1 $(get-extip) 2>/dev/null | tail -1 | awk '{print $2}'
}
get_gw_by_iface2(){
# Return router ip of interface (multitable)
# Usage: get_gw_by_iface IFACE
ip route list table all | awk '/default via/' | grep enp1s0 | awk '{print $3}'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment