Last active
January 12, 2022 18:54
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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