0

I have the following config:

Type    Name    Value

A       @       192.0.2.123
A       www     192.0.2.111
CNAME   test    @
CNAME   mail    @

Is it possible to temporary redirect the root domain to the www subdomain, so that when I type in the browser example.com, I will be redirected to www.example.com's 192.0.2.111 address. But when I type test.example.com or mail.example.com I will be get the 192.0.2.123 address?

My registrar is GoDaddy. I tried using the forwarding feature from GoDaddy's DNS management page, but it did not work at all and similar questions to this one had it done in htaccess on the server side.

4
  • 1
    DNS only tells a client what IP address it can find a server on. That server must also send a coherent response, by whatever protocol you wish (e.g. HTTP). That's why you have to edit your web server configuration. Aug 5, 2018 at 20:45
  • I'm not sure i understand the web server part. I can't have the 123.123.123.123 webserver redirect clients to 111.111.111.111 since it often times the server will be down - i.e. its meant to be private. That is why need to have it redirected by default to 111.111.111.111.
    – hrs
    Aug 5, 2018 at 21:13
  • You should have some other web server do it, then. Of course it doesn't make any sense that the server would be down often. Aug 5, 2018 at 21:14
  • Can i simply reverse it? Turn test and email into A records that point to 123.123.123.123 and change the root/@ to point to 111.111.111.111? Is it a good practice?
    – hrs
    Aug 5, 2018 at 21:29

1 Answer 1

1

I recommend looking at it from this perspective:

DNS is designed to be more static and aid in the translation of domains to IPs.

Web servers are designed to deliver web content and handle the intricacies of such. This includes URL rewriting and redirections and such.

That being said, your DNS entries should be as simple as pointing to what "box" you want people to reach when they use a specific domain.

In your specific case, I wonder if the 192.0.2.123 is even hosting a web server. If it only serves mail protocols or other things, it wouldn't be efficient to install a web server and configure it with the sole purpose of redirecting requests, but it is a possible solution. However, it is extremely common to have to handle the whole www.example.com vs. example.com redirection, but that is done using URL rewriting.

In this case, I would recommend setting the root domain and the www to the web server IP 192.0.2.111 and eliminate the CNAME records and instead change them to A records and point them to 192.0.2.123.

On another note, if your mail server handles receiving mail for your domain, you may need to set up an MX record for your root domain to point to 192.0.2.123. This will work (and is extremely common) because e-mail DNS lookups specifically look for MX records, vs A records.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .