0

I have configured the DNS records for a stage server for my application so that when someone visits stage.example.com and www.stage.example.com will work. (Actually if he visits the first he will be redirected to the second by the webserver.)

My zone configuration file for this setup is:

@         10800 IN A     1.2.3.4
stage     10800 IN CNAME example.com.
www.stage 10800 IN CNAME example.com.

and it works.

Now I want to configure my live server with the same behaviour (allow both www.example.com and example.com) while maintaining the existing functionality regarding the stage subdomain, but I cannot figure out the correct way to do it - or if it is even possible.

All my searches end up in examples about to configure it for one level subdomains, so I'm a bit lost here.

For example the following configuration is what I think I want, but it's not working

example.com           10800 IN A 5.6.7.8
stage.example.com     10800 IN A 1.2.3.4
www                   10800 IN CNAME example.com.
www.stage.example.com 10800 IN CNAME stage.example.com.

Any ideas/suggestions are most welcome.

Thank you in advance.

Sakis Vtdk
  • 111
  • 1
  • 4
  • It isn't clear to me what your problem is, or what specifically you are confused about? Just add more CNAME records? – Zoredache May 10 '16 at 19:15
  • My confusion is about how the CNAME records would look like, given that I would also need to add an extra A record for the live server. Apologies for not adding an example configuration of how I think they should look like, I will update my question in a bit. – Sakis Vtdk May 10 '16 at 19:42

2 Answers2

0

I don't think you need the .example.com appended to the second and last lines of your configuration. Your DNS server already knows you're dealing with .example.com as that's the parent domain.

So I believe you need to change:

example.com           10800 IN A 5.6.7.8
stage.example.com     10800 IN A 1.2.3.4
www                   10800 IN CNAME example.com.
www.stage.example.com 10800 IN CNAME stage.example.com.

to:

example.com           10800 IN A 5.6.7.8
stage                 10800 IN A 1.2.3.4
www                   10800 IN CNAME example.com.
www.stage             10800 IN CNAME stage.example.com.

Therefore you'll have a CNAME for www.example.com that resolves to 5.6.7.8 and a CNAME for www.stage.example.com that resolves to 1.2.3.4.

It seems as though you would also need an @ record for the domain like you show in the first code snippet in your question.

Tedwin
  • 559
  • 3
  • 13
  • I ended up doing something similar and it works. The thing that was confusing me was what were the names on the left and on the right side this config and their relationship with parent domain. A few digs later, I finally made some sense out of it. – Sakis Vtdk May 11 '16 at 07:27
0

Starting from Tedwin's answer and one of the first search results and combining them with a few digs I addressed my main confusion point:

The names on the left side of the configuration get the parent domain appended to them - unless already included.

So, this configuration

live      10800 IN A 5.6.7.8
stage     10800 IN A 1.2.3.4
www       10800 IN CNAME live
www.stage 10800 IN CNAME stage

Yields these dig results:

$ dig www.example.com

;; ANSWER SECTION:
www.example.com.        375 IN  CNAME   live.example.com.
live.example.com.       375 IN  A       5.6.7.8

and

$ dig www.stage.example.com

;; ANSWER SECTION:
www.stage.example.com.      375 IN  CNAME   stage.example.com.
stage.example.com.          375 IN  A       1.2.3.4

So in order for me to get it working as I want to, all I have to do is replace

live 10800 IN A 5.6.7.8

with

@ 10800 IN A 5.6.7.8

Sakis Vtdk
  • 111
  • 1
  • 4