Stay organized with collections Save and categorize content based on your preferences.
Linux Windows
When you create a virtual machine (VM) instance, Google Cloud creates an internal DNS name from the VM name. Unless you specify a custom hostname, Google Cloud uses the automatically created internal DNS name as the hostname it provides to the VM.
You can create a VM with a custom hostname by specifying any fully qualified DNS name. Custom hostnames are useful to maintain conventions or to support requirements for applications that expect a particular hostname.
Even when you specify a custom hostname, Google Cloud creates the Compute Engine internal DNS name. You can connect to your VM by using this automatically created internal DNS record. The internal DNS record resolves to the internal DNS name and not the custom hostname. With custom hostnames, you still need to create a corresponding DNS record in the appropriate zone, for example, by using Cloud DNS.
Before you beginSelect the tab for how you plan to use the samples on this page:
ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloudInstall the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
GoTo use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
JavaTo use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Node.jsTo use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
PythonTo use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
RESTTo use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
To get the permissions that you need to create VM with a custom hostname, ask your administrator to grant you the Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1
) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to create VM with a custom hostname. To see the exact permissions that are required, expand the Required permissions section:
Required permissionsThe following permissions are required to create VM with a custom hostname:
compute.instances.create
on the project compute.images.useReadOnly
on the image compute.snapshots.useReadOnly
on the snapshot compute.instanceTemplates.useReadOnly
on the instance template compute.networks.use
on the project compute.addresses.use
on the project compute.networks.useExternalIp
on the project compute.subnetworks.use
on the project or on the chosen subnet compute.subnetworks.useExternalIp
on the project or on the chosen subnet compute.instances.setMetadata
on the project compute.instances.setTags
on the VM compute.instances.setLabels
on the VM compute.instances.setServiceAccount
on the VM compute.disks.create
on the project compute.disks.use
on the disk compute.disks.useReadOnly
on the diskYou might also be able to get these permissions with custom roles or other predefined roles.
LimitationsYou must manually configure the DNS record for your custom hostname. Custom hostnames are not resolved by the automatically created records provided by Compute Engine internal DNS. You can use any of the following to host the DNS record for the custom hostname:
any other public DNS name server
You cannot change a custom hostname after you have created the VM.
Custom hostnames are set in the guest environment using hook scripts which integrate with the guest networking software. Linux operating systems that don't have a script to integrate with the guest network software might not have the correct hostname.
For the full list of operating system versions that support custom hostnames, check the guest environment support in Operating system details.
Naming conventionCustom hostnames must conform to RFC 1035 requirements for valid hostnames. To meet these requirements, custom hostnames must meet the following format specifications:
[a-z]([-a-z0-9]*[a-z0-9])?
.Not valid: contains a single label
my-host1234
Valid: contains three labels concatenated with dots
my-host1234.example.comCreate a VM with a custom hostname Console
In the Google Cloud console, go to the Create an instance page.
Specify a Name for your VM. For more information, see Resource naming convention.
Expand the Advanced options section, and then do the following:
Make additional VM customizations, as needed.
To create and start the VM, click Create.
Next step: Configure your DNS records. For more information, see Managing records.
gcloudUsing the Google Cloud CLI, follow the instructions to create an instance from an image or a snapshot, add the --hostname
flag, and use the gcloud compute instances create
command as follows:
gcloud compute instances create VM_NAME \ --hostname=HOST_NAME
Replace the following:
VM_NAME
: the name of the VMHOST_NAME
: the fully qualified domain hostname that you want to assignFor example, to create a VM myinstance
with the custom hostname test.example.com
, run the following command:
gcloud compute instances create myinstance \ --hostname=test.example.com
Next step: Configure your DNS records. For more information, see Managing records.
TerraformYou can use a Terraform resource to create an instance with a custom hostname by using the hostname
argument.
Next step: Configure your DNS records. For more information, see Managing records.
Go Java Node.js Python RESTFollow the API instructions to create an instance from an image or a snapshot, and specify the hostname
field in the request body.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances { "name": "VM_NAME", "hostname": "HOST_NAME", ... }
Replace the following:
PROJECT_ID
: your project IDZONE
: the zone where you want to create the VMVM_NAME
: the name of the VMHOST_NAME
: the fully qualified domain hostname that you want to assignFor Linux VMs, you can verify the hostname by running the hostname -f
command on the VM.
You can also verify the custom hostname by using the Google Cloud console or the Google Cloud CLI.
ConsoleTo view the custom hostname for your VM, go to the VM instances page.
Click the instance name to open the VM instance details page.
Review the Hostname section. The Hostname field is visible only if a custom hostname is set.
To view the custom hostname for your VM using gcloud compute
, use the instances describe
sub-command with a --format
flag to filter the output. Replace VM_NAME
with the name of the VM.
gcloud compute instances describe VM_NAME \ --format='get(hostname)'
For example, to view the custom hostname for a VM named myinstance
, run the following command.
gcloud compute instances describe myinstance \ --format='get(hostname)'
The output might resemble the following:
test.example.com
If a custom hostname is not set, the output for this command is blank.
What's nextExcept as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["Google Cloud automatically generates an internal DNS name for each VM, which is used as the default hostname unless a custom hostname is specified."],["Custom hostnames can be defined for VMs using fully qualified DNS names, but you still need to configure a corresponding DNS record in a zone like Cloud DNS to resolve it."],["Creating a VM with a custom hostname can be done through the Google Cloud Console, gcloud CLI, Terraform, or various programming languages like Go, Java, Node.js, and Python."],["Custom hostnames must adhere to RFC 1035 requirements, including having at least two labels, with each being 1-63 characters long and concatenated with dots."],["Verifying the custom hostname is possible by running the `hostname -f` command on the VM, using the Google Cloud Console, or using the `gcloud compute instances describe` command."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4