Skip to content

Instantly share code, notes, and snippets.

@Juravenator
Last active January 12, 2022 18:54
Show Gist options
  • Save Juravenator/2aca8d452056f4f02a28fbb00a6d6cb9 to your computer and use it in GitHub Desktop.
Save Juravenator/2aca8d452056f4f02a28fbb00a6d6cb9 to your computer and use it in GitHub Desktop.
get the IP of your machine, that is get the IP of the interface that the default route points to
# get the interface name that the default route points to
# then get ip(v4) address info of that interface
# filter out all the ip addresses, take the first entry
ip -4 addr show dev "$(awk '$2 == 00000000 { print $1 }' /proc/net/route)" | awk '$1 ~ /^inet/ { sub("/.*", "", $2); print $2 }' | head -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment