Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to foward some domains to another. The scenario is quite easy:

  • domain example.com is the primary domain

  • the domain example.net should be forwarded to example.com

  • all set up subdomains should be as well

As a DNS my machine is running bind and my configs look like this:

named.conf:

zone "example.com" {
     type master;
     file "/etc/bind/db.example.com";
     notify yes;
     allow-transfer{
         208.79.240.3;
         208.79.241.3;
     };
};

zone "example.net" {
     type master;
     file "/etc/bind/db.example.net";
     notify yes;
     allow-transfer{
         208.79.240.3;
         208.79.241.3;
     };
};

db.example.com:

$TTL    1d
@   IN      SOA     ns.example.com.   dns.example.com.  (
                                    2012021204      ;serial
                                    8H      ; refresh
                                    2H      ; retry
                                    4W      ; expire
                                    1D)     ; minimum
                        IN      NS      ns
                        IN      NS      ns1.rollernet.us.
                        IN      NS      ns2.rollernet.us.
ns                      IN      A       78.46.106.248
ns1.rollernet.us.       IN      A       208.79.240.3
ns2.rollernet.us.       IN      A       208.79.241.3

@                       IN      MX      10      mail
@                       IN      MX      100     mail.rollernet.us.
@                       IN      MX      100     mail2.rollernet.us.
@                       IN      A       78.46.106.248
mail                    IN      A       78.46.106.248
www                     IN      A       78.46.106.248

db.example.net

$TTL    1d
@   IN      SOA     ns.example.net.   dns.example.net.  (
                                       2012021208      ;serial
                                       8H      ; refresh
                                       2H      ; retry
                                       4W      ; expire
                                       1D)     ; minimum
                        IN      NS      ns.example.com.
                        IN      NS      ns1.rollernet.us.
                        IN      NS      ns2.rollernet.us.
ns                      IN      A       78.46.106.248
ns1.rollernet.us.       IN      A       208.79.240.3
ns2.rollernet.us.       IN      A       208.79.241.3
@                       IN      A       78.46.106.246
mail                    IN      CNAME   mail.example.com.
www                     IN      CNAME   www.example.com.

The forwarding works fine so far and all access to (www.)example.net is forwarded to (www.)example.com.

The only thing I am missing is that the addressbar in my browser is switching to (www.)example.com when I'm accessing (www.)example.net. How can I make this happen?

share|improve this question
add comment

3 Answers

Not via DNS. What you want is a URL redirect, possibly via HTTP.

share|improve this answer
    
He specifically does not want the URL to change. This means he needs either a proxy or duplicate DNS records. –  adaptr Feb 13 '12 at 11:19
    
No, actually I want the URL to change in the addressbar. I just thought that'd be possible with DNS as well. Guess I have to switch to a mod_rewrite solution then. –  Moritz Feb 13 '12 at 16:30
add comment

If you want to to simple go to the same ip address, then a simple CNAME will suffice.

But I gather you want to actual redirect, so you will have to use http redirect. Through Bind/dns redirect is not possible.

Since this is a simple catch all redirect then with apache it is a simple as these couple of lines:

 <VirtualHost *:80>
   ServerName example.net
   ServerAlias www.example.net *.example.net
   Redirect permanent / http://www.example.com/
 </VirtualHost>
share|improve this answer
    
Oh sweet. That actually fixed it as simple as I hoped it could be done! Thanks a lot :) –  Moritz Feb 13 '12 at 21:32
add comment

You can't.

If both domains need to end up at the same machine, then both domains need to contain identical A records for their respective labels.

If the data in the zone file is all relative, you can use the same zone file for both zones.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.