9

Does Google Cloud provide public hostnames for their Compute instances?

AWS seems to generate public 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 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).

1

4 Answers 4

8

No, GCE doesn't offer hostnames for an instance. It does assign external IP addresses for each instance. Associating a DNS record with your instance is the only method to generate a hostname.

GCE does have built in private hostnames, inside the same network. For example two instances in the same VPC can ping each other by name

Instance 'test-instance': start server on :8080
Instance 'second-instance': curl test-instance:8080
// Response 'Hello World'
4
  • Thank you, but I'm only interested in public hostnames. For this association with a DNS record, is it something that I can easily do for free (or totally through Google Cloud without having a domain name)? Commented Dec 5, 2018 at 1:39
  • 1
    You have to own a domain, or you can use the GCP DNS to create an internal zone.
    – FridayPush
    Commented Dec 5, 2018 at 1:41
  • Thank you. So, I guess this means I can't :( Commented Dec 5, 2018 at 1:43
  • I recommend that you submit a Feature Request. Google will consider the need based on its feasibility, or the number of customers who ask for it, but I can't guarantee an implementation or provide you with an ETA for it. Rest assured that Google strives on improving its products and that your feedback helps us do just that. Commented Dec 7, 2018 at 14:24
4

No. Source: FridayPush's answer (thanks! from his profile, seems worthy of trust for Google-Cloud things :-)).

The reason I wrote a separate answer is to make it clear that you can't have a public hostname totally through Google Cloud. You can either have an internal hostname totally through Google Cloud, or you'll need to do something outside of Google Cloud (e.g., own a domain name) to have a public hostname.

1
  • You could have marked FridayPush's answer as the solution instead.
    – Dale Ryan
    Commented Sep 7 at 2:52
2

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) 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
0

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:

# 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:

# (sed removes the trailing dot)
$ dig +short -x $(curl -s icanhazip.com) | sed "s/.$//"
150.81.88.34.bc.googleusercontent.com
2
  • For this method I must know the ip. (I mean if I already know the ip, then why I bother about its text alias?) Commented Dec 21, 2023 at 7:14
  • Sometimes you need a name, not an IP. For example in Kafka it's difficult to use IPs, you have to force it (stackoverflow.com/questions/65160810/…). But I don't remember what I needed it for, but I did and that's why I provided this answer - based on my own experience. Commented Dec 22, 2023 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.