问题
This is a question in two parts:
- Do GCE instances have a stable public DNS name? The default DNS name for instance with public IP a.b.c.d seems to be d.c.b.a.bc.googleusercontent.com
If yes, what's the best way to obtain this information? Here's the hack I've been using thus far:
EXTERNAL_IP=$(curl -s http://bot.whatismyipaddress.com/) EXTERNAL_DNS=$(dig +short -x ${EXTERNAL_IP})
回答1:
reverse lookup is okay to do, for IP address you would probably prefer using gcutil https://developers.google.com/compute/docs/gcutil/tips
EXTERNAL_IP=$(gcutil getinstance --format=csv --zone=[your_zone] [your_instance] | grep external-ip | cut -d "," -f 2)
来源:https://stackoverflow.com/questions/17688956/do-google-compute-instances-have-a-stable-public-dns-name