Skip to content

Instantly share code, notes, and snippets.

@jnerin
Last active September 25, 2020 10:39
Show Gist options
  • Save jnerin/56ff79c5872855fa8957f6cccdbf1587 to your computer and use it in GitHub Desktop.
Save jnerin/56ff79c5872855fa8957f6cccdbf1587 to your computer and use it in GitHub Desktop.
Get external IP from commandline by querying some DNS servers
# Faster with dig
dig -4 +short myip.opendns.com @resolver1.opendns.com # -4 needed to force ipv4 connectivity as resolver1.opendns.com doesn't return any result for this over ipv6
dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"' # IPv4
dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com | tr -d '"' # IPv6
# Slower with curl
curl -4 https://diagnostic.opendns.com/myip
curl -6 https://diagnostic.opendns.com/myip
curl -4 https://icanhazip.com
curl -6 https://icanhazip.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment