Netlify DNS CNAME records not working

Problem

Hi,

I am trying to point one of my subdomains (stg.groovly.fm) to a Netlify-hosted website (https://groovly-dev.netlify.app/) via a CNAME DNS record so that navigating to https://stg.groovly.fm is identical to navigating to https://groovly-dev.netlify.app/ but I get a 404 (not found) error from Netlify for the former, while the latter works fine.

Both ping and dig commands seem to succeed (see output below). Also none of my other CNAME records configured on Netlify’s DNS seem to work either.

Am I missing something here? Any ideas / help is appreciated!

DNS Config

  • Netlify site url: https://groovly-dev.netlify.app/
  • Top-level domain: groovly.fm (managed via Netlify DNS)
  • CNAME record config:
    • name: stg
    • value: groovly-dev.netlify.app
    • TTL: default

HTTP Error

  • Request URL: https://stg.groovly.fm/
  • Status Code: 404
  • Remote Address: 18.230.52.212:443
  • Referrer Policy: strict-origin-when-cross-origin

Command output for ping

$ ping -c 1 stg.groovly.fm

PING *groovly-dev.netlify.app* (18.230.52.212): 56 data bytes
64 bytes from 18.230.52.212: icmp_seq=0 ttl=46 time=43.220 ms

--- groovly-dev.netlify.app ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 43.220/43.220/43.220/0.000 ms

Command output for dig

$ dig stg.groovly.fm

; <<>> DiG 9.10.6 <<>> stg.groovly.fm
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30638
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;stg.groovly.fm.			IN	A

;; ANSWER SECTION:
stg.groovly.fm.		3600	IN	CNAME	groovly-dev.netlify.app.
groovly-dev.netlify.app. 20	IN	A	18.230.52.212

;; Query time: 142 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Thu Sep 24 11:19:47 -03 2020
;; MSG SIZE  rcvd: 96

Hi @martinzen! Welcome to netlify community.

Adding your custom domain to the site in our UI is the next step. You can do that right here: Netlify App.

Let us know how that goes!

Hi Laura, thanks for your answer.

The custom domain for the main site is already configured (groovly.fm) and working. All I’m trying to do is point a subdomain for the main site (dev.groovly.fm) via a CNAME record so that it points to another Netlify site (https://groovly-dev.netlify.app).

In summary:

I’m pretty sure the problem is at the Netlify content-serving level since the DNS seems to respond correctly as per my initial post.

Any ideas of what might be going on here?

Hi, @martinzen, there are two steps to getting this working.

One is adding the custom domain here:

I don’t see dev.groovly.fm added there yet. The other is to have DNS record in place and I don’t see that when I test:

$ dig dev.groovly.fm CNAME  +noall +answer

; <<>> DiG 9.10.6 <<>> dev.groovly.fm CNAME +noall +answer
;; global options: +cmd

Did you remove those now? If you want add those and troubleshoot this further, please let us know.

Hi Luke,

That doesn’t work unfortunately. My custom domain is already added to the main site (groovly.fm). When I try to also add the domain to the other Netlify site groovly-dev.netlify.app I get an error saying “Another site is already using this domain” which makes sense because it was added to the main site.

All I’m trying to do is have the main site’s Netlify-managed DNS point to the secondary site under an alias so that instead of having to navigate to https://groovly-dev.netlify.app/I can more conveniently navigate to dev.groovly.fm.

Please let me know if this is possible or if I ran into a limitation of Netlify’s DNS.

Hi, @martinzen, It should be possible to add “dev.groovly.fm” here:

https://app.netlify.com/sites/groovly-dev/settings/domain#custom-domains

If you try to add just groovly.fm there will be an error because that custom domain is already used on a different site on the same account. However, if you add the custom domain with the dev subdomain in front of it, that subdomain is not in use and should work.

If it does not, please let us know.

Hi Luke,

Thanks a lot, that worked, much simpler than I thought.

I was trying to add the top-level domain groovly.fm instead of the subdomain (api.groovly.fm). It would probably we useful to clarify this in the docs to avoid confusion.

Cheers,

What proposed changes would you make to the documentation, @martinzen? Happy to take your feedback to our documentation team, but my team is struggling to understand the shortcomings that you found in the docs, so some more explanation would be great to help us understand.

Thanks in advance!

Hi,

The docs clearly mention that it’s possible to point subdomains to other services which made me think that the way to achieve that was to point the secondary Netlify site (in my case, groovly-dev.netlify.app) to said subdomain (for me it was stg.groovly.fm) via manually adding a CNAME record to the primary site’s DNS config.

But it turns out that doesn’t work (I got a 404 from Netlify). Instead, the way to achieve it is to go to the secondary site, add the subdomain in there (clicking “yes” when asked if you owned the domain) and that would add the CNAME record onto the primary site’s DNS. Both approaches seem to produce the exact same DNS record, but the manual one just doesn’t work, not sure why.

I would suggest adding a paragraph explaining the (probably frequent) use case of having to point a subdomain to another Netlify site citing the steps described above by Luke.

Hope I didn’t miss anything. Thanks a lot for your great support.

Cheers,

2 Likes

Hmm, that’s odd, these instructions are correct:

The docs clearly mention that it’s possible to point subdomains to other services which made me think that the way to achieve that was to point the secondary Netlify site (in my case, groovly-dev.netlify.app ) to said subdomain (for me it was stg.groovly.fm ) via manually adding a CNAME record to the primary site’s DNS config.

Nowhere do those docs say “create a second site and put the hostname on it, to configure this hostname for the secondary service”

This workflow you describe next is not correct:

Instead, the way to achieve it is to go to the secondary site, add the subdomain in there (clicking “yes” when asked if you owned the domain) and that would add the CNAME record onto the primary site’s DNS.

The CNAME record should be created manually in the DNS UI if it is for a separate service. Applying the hostname to the site will cause a failure there.

So I guess I am still confused. Thanks again for your help!

I completely agree with @martinzen here. I ran into exactly the same problem here. The docs are indeed misleading. Everything Martin said is accurate, including critique of the documentation.

TLDR:
Essentially, this whole problem boils down to an undocumented difference between how you map subdomains. If you are mapping a non-netlify website to your primary domain, you need to create a CNAME (as documented). If you are mapping another netlify website/app to your primary domain, you need to add a custom domain to the netlify website/app.

Just as Martin, I am using Netlify to deploy and manage DNS for both a main site and a secondary site I want to map to a subdomain. When trying to make a netlify.app connect to a subdomain at whateverApp.MainSite.com, you have to add whateverApp.MainSite.com as a custom domain on the app. Instead, the docs suggest that you should add a CNAME record within the DNS manager settings on MainSite.com. When you do this, as Martin said, you get a 404 and the subdomain mapping does not work, with no helpful error messaging.

To clarify an area that may be leading to this confusion. Where you, (@fool) say:

There is no separate service. Martin (and I) are both only using Netlify.

One other point that might be confusing is that Martin says that after adding the subdomain.MainSite.com to the netlify.app, it shows a new CNAME record on MainSite. Actually, when you go to your netlify console-> MainSite-> Domain Settings-> MainSite.com-> Options → DNS Settings and look at your DNS records, a new record shows up for ‘NETLIFY’, which is not a type you can pick if you ‘Add new record’. This is quite confusing and would be a welcome addition to the documentation.

Hi @mattador,

Thanks for the feedback, but I disagree to some extent. The docs are correct in saying that you need to add a CNAME in your DNS Provider including if DNS is managed by Netlify. Regardless of who the DNS is hosting, what doesn’t change is you need to connect the domain to a Netlify site.

NETLIFY type records are nothing special, they’r A/CNAME records, but marking them as NETLIFY records helps you identify which one is added by Netlify and which is not.

Now in your case, after adding the CNAME entry inside Netlify DNS panel, if you had added the domain in site settings, it would still have worked. Adding the site to site settings is a compulsory step. Even when you add the domain to a site, that’s what the UI does, it adds a record automatically to the DNS Zone.

To summarise, the steps remain the same:

  1. Add the domain in site settings.
  2. Add the CNAME entry in your DNS provider.

Was trying to get subdomain to work with Netlify for 2 days before I stumbled on this answer and finally got it to work.

I too feel the doc should be updated. I followed Configure External DNS, which only mentions about how we need to configure CNAME with our DNS provider (in my case, Cloudflare).

No where is it mentioned that the custom subdomain has to be added to Netlify’s domain (with the warning). If the doc had contained this information, I could’ve gotten it to work sooner.

I’m suggesting this so others don’t get stuck like I did :slight_smile:

Hi, @shreyas. About this:

The documentation does cover this. This is in the “Assign a domain to a site” documentation here:

https://docs.netlify.com/domains-https/custom-domains/#assign-a-domain-to-a-site

The information you linked to above follows later in the documentation. Here is a screenshot to clarify:

So, step 1 is always to add the domain name to the site’s custom domain setting. Step 2 is to create the required DNS record.

If you are not using Netlify DNS making the DNS record is a manual process. If Netlify DNS is being used, the creating of the DNS record is automatic.

Thanks for this thread :raised_hands: The documentation is not clear. I would recommend a screenshot of what domain settings we should be modifying and possibly some form validation when trying to add a CNAME to our netflify.app address. Even a tooltip of how you assign a NETLIFY DNS record with a link would be helpful.

i don’t think this is a documentation issue so much as a UX issue.

thanks for the feedback, chris-feist. We’ll try and make things more clear in the future!

I’m facing the same issue (external subdomain + CNAME already setup + 404 thrown by Netlify).

What am I missing?

  • Already setup CNAME on the external DNS provider (aws)
  • Already added DNS Record inside Netlify App
  • Trying it out w/ the browser I get 404
  • Trying it out w/ dig I get the actual, correct CNAME

We would need a domain to check @arthurmarinho :slight_smile:

just adding my 2c here, I also struggled to get this set up and could not understand why it wasn’t working. we have a domain registered with netlify DNS and i wanted to add a CNAME subdomain record to point directly to a deploy preview. This did not work until I added the subdomain to the site config domains as well and I could not find this mentioned anywhere (nor does it seem very intuitive).

This blog post made it seem as though no additional configuration inside netlify was needed: How to Set Up Netlify DNS - Custom Domains, CNAME, & Records

This page also makes it seem as though there is no additional configuration needed outside of the Netlify DNS config: DNS records | Netlify Docs

edit: Nevermind, adding the DNS registration in the site domains actually just links it to the main (production) deploy. I don’t see a way to add a CNAME registration directly to a deploy preview. This could be accomplished sort of with branch deploys, but this takes some clicking around to accomplish for any branch we want this to happen for. I don’t understand why I can’t just add a CNAME record that points to a deploy preview URL. Similar to others, a dig on the CNAME record returns the proper deploy preview URL, however in the browser I get a netlify “Site not found” error