Working with CNAME records and your DNS provider
- English
- 日本語
Once you're ready to route traffic to a Fastly service using your domain name, you must associate the domain with your Fastly service and then update your DNS records to point to Fastly by setting up a CNAME record for the domain. While the steps you follow when setting up a CNAME record for your domain will vary depending on your DNS provider, in general you'll need to input a specific value from Fastly that communicates to your DNS provider where and how to route through Fastly’s network.
This guide helps you find the information you'll need from Fastly to set up a CNAME record with your DNS provider including how to choose the right hostname value for the record. It also includes an example and a list of common mistakes to help you avoid and troubleshoot problems.
IMPORTANT: Fastly is not a DNS provider. The steps you follow when setting up a CNAME record for your domain will vary depending on your DNS provider. You must have access privileges to modify DNS records for your domain.
Before you begin
Keep in mind the following CNAME configuration limitations. Specifically:
- Shared TLS domain incompatibility. You can't add a CNAME record for a shared TLS domain.
- Apex domain incompatibility. You can't use a CNAME record if you plan to use Fastly on your apex domain (e.g.,
example.comrather thanwww.example.com). Check out our guide to using Fastly with apex domains for more details.
Choosing the right Fastly hostname value for your CNAME record
When you set up your CNAME record, you'll need to enter a hostname value. This value is used to communicate to your DNS provider where and how to route through Fastly’s network.
The value you choose will differ based on:
- the standard HTTPS (TLS) support requirements for your domain, including whether or not HTTP/2 is enabled.
- any custom TLS options purchased for your domain.
- whether or not you choose to limit your traffic to the North American and EU network or use Fastly's global network.
In the next sections you can find recommendations based on the most common criteria.
Non-TLS hostnames and limiting traffic
If you don't require TLS support and only need to accept HTTP (Port 80) connections, use one of the following values for the CNAME record:
| Location to route traffic | CNAME record value |
|---|---|
| Fastly's entire global network | dualstack.nonssl.global.fastly.net |
| North American and EU POPs only | dualstack.nonssl.us-eu.fastly.net |
HINT: Fastly's non-TLS hostnames refuse HTTPS connections (port 443) to prevent TLS certificate mismatch errors.
TLS-enabled hostnames
If using Fastly TLS, you must use the assigned CNAME record value provided in the Fastly web interface. Using an incorrect value may cause HTTPS (port 443) visitors to receive a TLS certificate mismatch error.
HINT: This section only applies to Fastly-shared hostnames before v.sni alphabetically. Fastly-shared hostnames from v.sni onwards have IPv6 enabled by default.
The format for the CNAME record value is <letter>.sni.global.fastly.net. Hostnames from v.sni onwards alphabetically have IPv6 enabled by default. For hostnames before v.sni alphabetically, prefix the value with dualstack to enable both IPv4 and IPv6 connections.
| TLS type | CNAME record value |
|---|---|
| Fastly TLS | <letter>.sni.global.fastly.net |
| Fastly TLS with IPv6 support | dualstack.<letter>.sni.global.fastly.net |
To locate the CNAME record value:
- Log in to the Fastly control panel.
- Go to Domains.
- Locate the domain you would like to route to Fastly.
- Click View/edit next to the appropriate certificate to view DNS details.
- Locate the CNAME record value under the DNS details section.
HINT: If you want to limit traffic to a certain region while using a TLS-enabled hostname, contact support.
Setting up the CNAME record with your DNS provider
Once you've determined the appropriate Fastly hostname for your domain, the next step is to set up a CNAME record for your domain. Refer to your DNS provider's documentation for exact instructions on how to create or update a CNAME record. If you run your own DNS server or are familiar with the format of BIND zone files, the CNAME record would look similar to this:
www.example.com. 3600 IN CNAME nonssl.global.fastly.net.In the above example, the domain set up on Fastly is www.example.com., with a time-to-live (TTL) of 3600 seconds (1 hour), the Record Type is CNAME, and the Fastly hostname value is nonssl.global.fastly.net. because TLS support isn't required and traffic will be routed through Fastly's entire global network.
Best practices when updating a DNS CNAME record
- Be sure you've added all domains you want served by Fastly to the appropriate service. If you don't and you point your domain to Fastly, an
unknown domainerror will occur. - Make sure your service is properly configured. You can test a Fastly service on your local machine by using curl and testing setup before changing domains.
- If you have multiple hostnames on the same domain (e.g.,
api.example.com,www.example.com,app.example.com), you can use a DNS wildcard record (*.example.com) at your DNS provider so only a single CNAME record is created and maintained. You should also add either a matching*.example.comdomain or the individual domains to your Fastly service. - Before configuring a CNAME record to point to Fastly, change your service configuration to lower the CNAME's TTL to a small number (we suggest 60 seconds) and wait for the old TTL to expire. Creating a DNS CNAME record for your domain after the TTL expiration ensures you have an easy way to roll back changes if you encounter an issue. Once you confirm everything is working properly using Fastly, you can increase the TTL to its original value.
Checking your CNAME record
To check your CNAME record, run the following command in a terminal window:
$ dig www.example.com +shortYour output should appear similar to the following:
nonssl.global.fastly.net.151.101.117.57In most cases, the hostname displayed first will be your current Fastly hostname (in this case, nonssl.global.fastly.net.). If you don't see a Fastly hostname in the output or if you see an incorrect Fastly hostname, then either your CNAME isn't properly set at your DNS provider or an older CNAME record is still cached by your local DNS resolver.
You can use various online DNS query tools like OpenDNS Cache Check or whatsmydns.net to test the current DNS responses from the different DNS resolvers worldwide.
Example: Pointing www.example.com to Fastly with TLS
In this scenario, you own example.com and want www.example.com served by Fastly over HTTPS using Fastly TLS. The example uses the www subdomain because you can't use a CNAME record with an apex domain (example.com). For more information, check out using Fastly with apex domains.
Add the domain to your service. Add
www.example.comto your Fastly service and activate the new service version. If you skip this step and point your DNS at Fastly, visitors will receive anunknown domainerror.Find your CNAME record value. In the Fastly control panel, go to Domains, locate
www.example.com, click View/edit next to the appropriate certificate, and copy the CNAME record value under DNS details. In this example, the value isp.sni.global.fastly.net. Becausepcomes beforev.snialphabetically, you can add thedualstack.prefix to enable both IPv4 and IPv6 connections, which gives youdualstack.p.sni.global.fastly.net.Lower the TTL. Before changing anything, lower the TTL on the existing record for
www.example.comto 60 seconds and wait for the old TTL to expire. This gives you a quick way to roll back if you encounter an issue.Create the CNAME record at your DNS provider. The exact steps vary by provider, but the record contains the following values:
Field Value Type CNAMEName or host wwwValue or target dualstack.p.sni.global.fastly.netTTL 60In BIND zone file format, the record looks like this:
www.example.com. 60 IN CNAME dualstack.p.sni.global.fastly.net.Check the record. Run the following command in a terminal window:
$ dig www.example.com +shortYour output should appear similar to the following:
dualstack.p.sni.global.fastly.net.151.101.117.57If you don't see a Fastly hostname, either the CNAME isn't properly set at your DNS provider or an older record is still cached by your local DNS resolver. Use a tool like whatsmydns.net to check the responses from DNS resolvers worldwide.
Restore the TTL. Once you confirm everything is working properly, increase the TTL to its original value.
Common mistakes
Here are some common problems people encounter when setting up CNAME records for Fastly.
Pointing DNS at Fastly before adding the domain to your service
- Symptom: Visitors see an
unknown domainerror. - Cause: The domain isn't associated with a Fastly service, so Fastly doesn't know how to handle the request.
- Fix: Add the domain to your service and activate the new version before you change your DNS records.
Using the wrong hostname for TLS
- Symptom: HTTPS visitors receive a TLS certificate mismatch error.
- Cause: The CNAME record value doesn't match the value assigned to your domain.
- Fix: Copy the CNAME record value from Domains > View/edit > DNS details in the Fastly web interface.
Using a non-TLS hostname for an HTTPS site
- Symptom: HTTPS (port 443) requests fail or are refused.
- Cause: Fastly's non-TLS hostnames refuse HTTPS connections to prevent TLS certificate mismatch errors.
- Fix: Replace the non-TLS hostname with the TLS-enabled CNAME record value from the Fastly web interface.
Using a CNAME record with a shared TLS domain
- Symptom: The CNAME setup doesn't work regardless of which hostname you use.
- Cause: You can't add a CNAME record for a shared TLS domain.
- Fix: Use a different TLS option for your domain.
Skipping the TTL change
- Symptom: You encounter a problem after switching DNS records, and rolling back takes hours.
- Cause: The previous record's long TTL means resolvers continue to use the cached value until it expires.
- Fix: Before making the change, lower the TTL to a small number (we suggest 60 seconds) and wait for the old TTL to expire.
Assuming the change failed because the DNS record changes haven't propagated
- Symptom: You're not seeing the changes in your web browser, and
digdoesn't show a Fastly hostname after you update the record. - Cause: Either the CNAME isn't properly set at your DNS provider, or an older record is still cached by your local DNS resolver.
- Fix: Confirm the record at your DNS provider, then use a tool like whatsmydns.net to check responses from resolvers worldwide.
Removing CNAME records
If you deactivate a service, delete a service, or cancel your account, we strongly recommend modifying or deleting any CNAME records pointing to Fastly. Follow the instructions on your DNS provider's website. Doing so will minimize the risk of unauthorized use of your domains.