Adding a domain you own to your DigitalOcean account lets you manage the domain’s DNS records with the control panel and API. Domains you manage on DigitalOcean also integrate with DigitalOcean Load Balancers and Spaces to streamline automatic SSL certificate management.
A subdomain is an additional hostname of a domain. Subdomains can point traffic to a specific IP address or other parts of a website. For example, a company could use the domain
example.com to direct traffic to their website’s home page and use the hostname
support.example.com to send traffic specifically to their support portal that resides on another service or server.
In this tutorial you’ll set up an A record on your domain that directs traffic from a new hostname to a target IP address. This workflow is meant to give a basic understanding of how to add a new hostname to your domain name and create records for it. You can use this workflow to set up a hostname using any type of DigitalOcean supported DNS record.
You can also set up other types of DNS records on a hostname for specific purposes, such as records specifying the domain’s mail servers or records containing public keys referenced by encryption services.
If you are setting up a new hostname that points to a different web directory on the same Droplet as your current domain name, follow this tutorial to set up your DNS record and then visit the Next Steps section of this article for tutorials on how to configure a new virtual host on your Droplet.
To follow along with this tutorial, you need to complete the following prerequisites:
example.com. You can purchase one from domain name registrars, such as domain.com
If you have not already added a domain to your DigitalOcean account, you can follow our DNS Quickstart guide on how to add a domain on DigitalOcean.
If you already have a domain name added to your account but are unsure of how to delegate it to use DigitalOcean’s name servers, see our Community tutorial on how to delegate your domain from several popular registrars. You’ll ensure that your delegation is correctly resolving in the next section of this tutorial.
In this step, you’ll check that your domain resolves correctly using DigitalOcean’s name servers.
Go to our Community DNS Lookup tool and enter your domain name into the search field, then click Search. The DNS Lookup tool returns any DNS records that reside at your domain name.
Scroll down to the NS Records section. The NS Records section should contain three NS records for the domain, each containing a DigitalOcean name server address in the data column.
If the NS records contain data with anything other than DigitalOcean’s name server addresses, your domain may not be correctly delegated. See our Community tutorial on how to delegate your domain to DigitalOcean’s name servers from popular registrars.
Alternatively, you can use the
dig command line tool to verify your domain’s delegation by running the command:
dig @ns1.digitalocean.com <YOUR-DOMAIN> NS
If the query returns anything other than DigitalOcean’s name servers in the
ANSWER SECTION of the results, your domain may not be correctly delegated.
;; ANSWER SECTION: example.com. 1800 IN NS ns2.digitalocean.com. example.com. 1800 IN NS ns1.digitalocean.com. example.com. 1800 IN NS ns3.digitalocean.com.
See our tutorial Retrieve DNS Information with
dig for more information.
In this step, you’ll add a new hostname to your domain and point it to a target IP address. This target IP address can be the public IP address of any of your Droplets or Load Balancers.
To add the hostname from the control panel, click Networking in the main menu. In the Domains tab, click the domain name you would like to add the new hostname to.
In the Create new record screen, click the A tab.
Enter the new hostname into the HOSTNAME field. The characters entered into the Hostname field append to your domain name and a preview of the hostname’s full address appears below the Hostname field. If your hostname contains non-ASCII characters (such as accents or other Unicode characters), you must convert it to punycode before adding it.
Enter the target IP address (the server you would like to direct traffic to) into the WILL DIRECT TO field. Leave the TTL (Time To Live) duration as is,
Click Create Record. The record is created at the new hostname.
In this step, you’ll verify that the DNS changes have propagated across the internet. Below are three different methods for verifying your DNS changes.
All DNS records have a TTL that specifies how long a record should remain in a resolver’s cache before the resolver should query a DNS name server for an updated set of records for hostname. This means if a DNS record has a TTL of 3600 seconds (1 hour), a resolver will cache the record for 3600 seconds after it receives the initial query for a hostname. DNS propagation is the process of allowing DNS records’ TTLs to expire in resolver caches across the internet. This is why your DNS changes may not be immediately apparent upon updating.
If you want to verify your DNS changes without needing to account for propagation times, use the
dig option to query DigitalOcean’s name servers directly.
Scroll down to the A Records section. An A record containing the data of your target IP address should exist in the A Records section. If no A record exists, check the DNS records section of your domain in the DigitalOcean Control Panel and ensure that the record was created. If the record exists, give the record at least 48 hours to propagate across the internet. If the record doesn’t exist, create it again using the steps in the Create a New Hostname with an A Record section.
Web Browser You can also enter the newly created hostname into your browser’s URL field to ensure that the new hostname is resolving to the correct website. If the website does not resolve, your server may need additional configuration (see the Next Steps section), or you may need to allow more time for the new DNS record to propagate across the internet.
dig (command line tool)
You can use BIND’s
dig tool to retrieve DNS record information directly from DigitalOcean’s name servers without having to account for propagation time.
dig is a robust DNS diagnostic tool native to macOS and Linux operating systems that you can access from the command line. If you are using Windows, see our tutorial Retrieve DNS Information with Dig.
dig to see if your DNS record has been set up correctly, enter the following command into your terminal:
dig @ns1.digitalocean.com <your new hostname>`
dig returns DNS record information about your hostname. In the ANSWER SECTION, your newly created A record should be visible. If no A record exists, check the DNS records section of your domain in the DigitalOcean Control Panel and ensure that the record was created. If the record was not created, try to create the record again using the steps in the Create a New Hostname with an A Record section.
If you are pointing your newly created hostname at a web application or a separate web directory on your server, your target Droplet or application may require additional network configuration to access it from the hostname. You can find more tutorials to help with this on our Community: