Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Google publish a DNS record for Google Compute Engine instances?

I'm running an occasionally-up server on Google Compute Engine. I'd prefer not to pay for a static IP address and just make use of an ephemeral IP address when the instance is running. Does GCE publish into DNS a mapping from instance name to ephemeral IP that I can use or CNAME to? E.g. something like instancename.projectname.googlecompute.com with a low enough TTL that it can be resolved to point to my instance's IP address fairly soon after it starts?

I can't find anything like this in the docs, but it's very surprising to me if it doesn't exist.

like image 912
Tim Dierks Avatar asked Sep 18 '14 21:09

Tim Dierks


People also ask

Does Google do DNS hosting?

Google Workspace gives you a unique DNS record to add to your domain. Google detects this record and verifies your domain ownership. Your domain's DNS records are typically hosted by your domain host (where you purchased your domain).

How does Google use DNS?

Google Public DNS uses Name Server (NS) records published in the DNS root zone and zones of top-level domains to find the names and addresses of the DNS servers that are authoritative for any domain. Some of those name servers also use anycast routing.


2 Answers

Yes, the only way to reach your instance by a DNS name is to create a DNS entry yourself, such as with a static A record pointing to a static IP address or a dynamic DNS entry pointing to your ephemeral address (which is what I do for my instances).

Compute Engine does not provide a pre-defined hostname, like App Engine does, pointing to app_name.appspot.com.

My DNS provider, freedns.afraid.org, makes DDNS rather simple. For a host you want to name, create a static A record, then click the DDNS link and it give you a wget or curl command line to run from a cron job on your VM instance.

But there are plenty of other DNS providers out there who can do something similar.

like image 173
Brian K Haney Avatar answered Oct 02 '22 08:10

Brian K Haney


Given that the answer to the actual question is no, this answer might still help those for whom it is sufficient to be able to obtain the ip adddress through scripting rather than needing to looking it up manually.

If having the gcloud command installed and setup, outputting the ip address of a running instance is possible using a list of rather long arguments. To easily show the currently assigned address, add a function like this to your shell initialization file:

get_gce_ip()
{
  local instance="${1%%.*}"
  gcloud compute instances list --filter="$instance" \
      --format='value(networkInterfaces[0].accessConfigs[0].natIP)'
}

With that function in place, accessing any host gets convenient using ssh instancename.googl after simply adding these two lines to .ssh/config

Host *.googl
  ProxyCommand nc `get_gce_ip "%h"` %p

Clearly these are not full substitutes for DNS entries, but in some cases they might help.

like image 32
sampi Avatar answered Oct 02 '22 07:10

sampi