DNS: forward root domain to www... when there are other DNS subdomains - dns

I currently have a DNS setup where all content and applications are hosted on the same cloud server - example.com.
The presentation website is on example.com, www is forwarded to example.com with a CNAME and then various internal apps, eg app.example.com, are also forwarded with CNAME records to example.com. NGINX running on my server takes it from there, routing subdomains to the different apps.
I'd like to host the presentational website on an external service, and I'm confused about how to update my DNS config - specifically what to do with my A record.
I'm ok with creating a CNAME for www that will forward www.example.com to my external hosting service. But example.com is still pointing to my own server... and if I have understood correctly, if I forward example.com to www.example.com, then all my apps at eg app.example.com will break.
What are my options for handling this ?
My idea (from searching around) is that if I want example.com to point to an external service, then I should
1) create a new domain api-example.com whose A record points to a server where all my apps are hosted
2) make CNAME records for all my app subdomains on example.com which point to api-example.com
3) forward example.com to www.example.com, and forward www.example.com to the external service.
Will this configuration work ? Is there a simpler way to get the same result ?

Your plan is fine, except for maybe one thing: generally, you can't have a CNAME record for the root (apex) of your domain. This means that your external presentation website hosting will have to provide an IP address, and you will create an A record that will point example.com to that address. Then you can have a CNAME record simply aliasing www.example.com to example.com.
Also make sure that you leave enough time between the steps, to make sure that all DNS TTLs expired so you don't encounter DNS caching issues.
For explanation (and possible workarounds) for domain apex CNAMEing issue, look at https://stackoverflow.com/a/33027309/1145196

Related

What is the correct DNS record setup for www subdomain?

I would like to set up my web app to use the "www" subdomain as my primary url. I'll be using a service to handle 301 redirects from my naked/apex domain to my subdomain (example.com -> www.example.com). What is the correct DNS record type for my "www" subdomain? Cant seem to find a clear answer on this.
An "A" record pointing to my websites IP address?
A "CNAME" pointing to my naked/apex domain?
It's CNAME. A record is pointing to the webserver IP address. CNAME will serve as an alias. Commonly when example.com and www.example.com points to the same application and hosted by the same server. To avoid maintaining two different records, it's a best practice to create an A record for example.com pointing to the server IP address and a CNAME record for www.example.com pointing to example.com

Bypass subdomain limit by hosting own DNS server

The following is more theoretical than practical, I want to test if I have understood the DNS system.
I'm currently renting a domain, lets call it example.com, from a provider.
I also own a server with a static ip.
Using the webinterface of my domain provider, I created an A-Record for my domain to point to my server.
Now everyone pinging example.com will find that A-Record (that should distribute itself to serveral more DNS servers) and thus ping my server.
Now I want a subdomain, which points to a different ip address.
My provider on the other hand won't let me create subdomains.
I can simply host an own DNS server at example.com, where I can add (arbitraryly) many records for any domain that is a subdomain to example.com (so not only subdomain.example.com but also subdomain.subdomain.example.com).
Now, if someone pings subdomain.example.com the following will happen:
They go to their favourite DNS server, which has an entry for example.com by now (due to distribution, see above)
Since there is no entry for subdomain.example.com, the will send an DNS request on udp port 53 to the A-Record ip behind example.com (my server)
My server will reply with the correct ip of subdomain.example.com
They send their ping to the correct ip
Is my understanding correct?
It's not far off, but there are more subtle things under the hood. If you want to host your example.com zone yourself, then you need to have your parent (.com) have NS records that point to your nameserver on your static IP. You would need to register that within your parent through your registrar that you bought the DNS registration with.
.com would need to host:
example.com. NS myns.example.com
myns.example.com. A YOURIP
And in your zone running on your machine, you would need something like:
example.com. SOA ....
example.com. NS myns.example.com
myns.example.com. A YOURIP
subdomain.example.com A SUBDOMINIP
If "subdomain" (your wording) is actually supposed to be in another zone enirely, then you need to use NS/A records to point to its DNS server (which can be the same).
You might go look for a good tutorial about how the DNS works in general. It will take you a lot further.

how to connect cloudflare root domain to AWS Elastic Beanstalk

I wish to setup Cloudflare so that both mydomain.com and www.mydomain.com will reach the same Elastic Beanstalk host.
I've created a CNAME for the "www" subdomain, it works great.
But how do I handle the mydomain.com DNS root entry? It's currently an A record, pointing to some IP, but in order to point to EB, I need to have a CNAME like "www", correct? If so, is it safe to somehow replace the A record with a CNAME despite the fact this is a root DNS entry rather than some subdomain..
thanks.
All you need to do is add a Page Rule
Match: mydomain.com/* and Redirect (301) to https://www.mydomain.com/$1
Or http if you’re not using SSL. The $1 means to copy the path from the original request.
Delete the A record from Cloudflare DNS Panel
Add a record with type CNAME and value as yourdomainname.com
This doesn't work on most DNS providers. However, Cloudflare has a feature called "CNAME flattening" that allows a CNAME Record to co-exist with other records at a domain's root. In practice, it doesn't act like a CNAME because when someone looks it up, Cloudflare resolves it internally, finds an A Record and returns the value. (This is how Alias A Records work on AWS Route 53, for example.)

How to allow CNAME pointed to my server / how to use subdomain for a different server?

We create custom web apps for businesses and for the first time a client of ours has asked that instead of using our subdomain and instead of using a custom domain for their web app they would like to use their own subdomain for a domain currently hosted on another server.
For instance our domain is webapp.com and their domain is business.com. They would like app.business.com to be point to our name servers so we can continue hosting the web app for them.
I know it's possible to do this because we currently have outgoing CNAMEs on our server for help desks, etc, that aren't hosted on our own server but are using subdomains of ours.
Could you help me with what our client has to do on their zone editing side and what we need to do on our WHM/cPanel side to allow this?
NOTE: We had the client create a CNAME for app.business.com. pointed to our nameserver ns1.webapp.com and then we created an add-on domain for business.com and subdomain for app.business.com but when you try to visit app.business.com it gets the "Sorry!" cPanel page.
Thank you!
Alright I figured out how to do it on my own after a lot of testing & thought I'd post here to help others out in case they run across this in the future.
For the server with the subdomain on it have them create an 'A' record for that subdomain pointing to your server's IP address like so:
subdomain.business.com. ((note the extra period at the end is required))
TTL: 14400
Record Type: A
Pointing To: Your server's IP address.
Now on your server's cPanel you will need to create an addon domain for THAT subdomain (ie subdomain.business.com) - not for the actual business.com domain but for the entire subdomain subdomain.business.com with the folder being the root folder wherever you would like it to show.
That worked for me!
The CNAME should not point to your nameserver but your subdomain f.e. client1.webapp.com.
An other solution could be to add the subdomain app.business.com to your server and the client add an A record for the subdomain to your ip.

Which DNS records should i have for several subdomains and naked domain?

We have 3 sites/apps hosted on 3 different locations (IP addresses):
Angular app:
app.domain.com on IP 1.1.1.1
Web Service:
api.domain.com on IP 2.2.2.2
Web Sit/Blog:
domain.com AND www.domain.com on IP 3.3.3.3
So, we want domain.com to go to www.domain.com.
What is the right, best practice way to solve following case?
What DNS records should we have?
The Google recommends 301 redirect (see https://support.google.com/webmasters/answer/93633). Therefore it is neceessary to use URL record. See https://support.dnsimple.com/articles/differences-between-a-cname-alias-url/ for example.
If your NS-server does not support URL records then you need to add URL rewrite rule on your web-server. In this case:
In first, you should create two same A-records for domain.com and www.domain.com on NS-servers. Also you can use CNAME-record instead of second A-record.
In second, configure redirection on your hosting server (3.3.3.3). In this article considers the similar solution for IIS or Appache web server..

Resources