Skip to content

Instantly share code, notes, and snippets.

@mtilson
Last active June 1, 2022 18:51
Show Gist options
  • Save mtilson/647c7b89ac8ecfa3efc1b9347858c07e to your computer and use it in GitHub Desktop.
Save mtilson/647c7b89ac8ecfa3efc1b9347858c07e to your computer and use it in GitHub Desktop.
how to get external IP on different clouds [linux] [aws] [gcp]

Common methods for AWS EC2 and GCP GCE

# AWS
$ dig +short myip.opendns.com @resolver1.opendns.com
18.224.203.147
# GCP
$ dig +short myip.opendns.com @resolver1.opendns.com
35.198.84.105
# AWS
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
"18.224.203.147"
# GCP
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
"35.198.84.105"
# AWS
$ curl http://checkip.amazonaws.com
18.224.203.147
# GCP
$ curl http://checkip.amazonaws.com
35.198.84.105
# AWS
$ curl icanhazip.com
18.224.203.147
# GCP
$ curl icanhazip.com
35.198.84.105
# AWS
$ curl ifconfig.me ; echo
18.224.203.147
# GCP
$ curl ifconfig.me ; echo
35.198.84.105

AWS EC2 only

# AWS
$ curl http://169.254.169.254/latest/meta-data/public-ipv4 ; echo
18.224.203.147

GCP GCE only

# GCP
$ curl "http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip" -H "Metadata-Flavor: Google" ; echo
35.198.84.105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment