Skip to content

Instantly share code, notes, and snippets.

@rafael-neri
Last active July 13, 2016 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafael-neri/7d79fc3508352270f109196b2d9fc4e1 to your computer and use it in GitHub Desktop.
Save rafael-neri/7d79fc3508352270f109196b2d9fc4e1 to your computer and use it in GitHub Desktop.
Check Default Interface To Internet
#!/bin/bash
# host we want to "reach"
host=google.com
# get the ip of that host (works with dns and /etc/hosts. In case we get multiple ipaddresses, we just want one of them
host_ip=$(getent ahosts "$host" | head -1 | awk '{print $1}')
# only list the interface used to reach a specific host/IP. We only want the part between dev and src (use grep for that)
ip route get "$host_ip" | grep -Po '(?<=(dev )).*(?= src)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment