Question: Does Google Cloud provide public hostnames for their Compute instances?

AWS seems to [generate public hostnames](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html#vpc-dns-hostnames) for their EC2 instances:

> 
> A public (external) DNS hostname takes the form ec2-public-ipv4-address.compute-1.amazonaws.com for the us-east-1 region, and ec2-public-ipv4-address.region.compute.amazonaws.com for other regions. We resolve a public DNS hostname to the public IPv4 address of the instance outside the network of the instance...
> 
> 
> 

**Similar question:**  

[This](https://stackoverflow.com/questions/25724351/google-cloud-public-hostname) seems like a similar question but (1) setting up a DNS seems like an overkill, (2) seems like I'll need to do some sort of thing outside of Google Cloud anyway or it isn't public (not sure), and (3) it could be outdated (2014).

Answer: 
GCE instances don't currently have a public DNS name for their external IP address. But there is now a `gcloud compute config-ssh` ([docs](https://cloud.google.com/sdk/gcloud/reference/compute/config-ssh)) command that's a pretty good substitute.

This will insert `Host` blocks into your `~/.ssh/config` file that contain the IP address and configuration for the host key.

Although this only helps with SSH (and SSH-based applications like Mosh and git+ssh), it does have a few advantages over DNS:

* There is no caching/propagation delay as you might have with DNS
* It pre-populates the right host key, and the host key is checked the right way even if the ephemeral IP address changes.

Example:

```
$ gcloud compute config-ssh
...
$ ssh myhost.us-west1-b.surly-koala-232

```
If your GCP instance has an external IP, ephemeral or static, then that IP address has public DNS entry that you can easily get with a reverse DNS lookup.

Example:

```sh
# get your external IP
$ curl icanhazip.com 
34.88.81.150

# do a reverse DNS lookup
$ dig +short -x 34.88.81.150
150.81.88.34.bc.googleusercontent.com.

```

A one-liner to get that public DNS entry:

```sh
# (sed removes the trailing dot)
$ dig +short -x $(curl -s icanhazip.com) | sed "s/.$//"
150.81.88.34.bc.googleusercontent.com

```