Bind9 Forwarders/Redirect
We are using Bind9 on our DNS servers. We have all of our zone files structured with the following format in our /var/named/slaves directory:
mywebsite.com.hosts
mysecondwebsite.com.hosts
Each .hosts file contains the following information:
$ORIGIN .
$TTL 3600 ; 1 hour
mywebsite.com IN SOA dns1.xxx.xxx. postmaster.xxx.xxx. (
2012042601 ; serial
3600 ; refresh (1 hour)
600 ; retry (10 minutes)
86400 ; expire (1 day)
3600 ; minimum (1 hour)
)
NS dns1.xxx.xxx.
NS dns2.xxx.xxx.
A 168.xxx.xxx.xxx
$ORIGIN mywebsite.com.
www A 168.xxx.xxx.xxx
Our named.conf file has the following info:
options {
directory "/etc";
pid-file "/var/run/named/named.pid";
recursion no;
notify yes;
listen-on { 10.xx.xx.xx; 127.0.0.1; };
allow-transfer { 10.xx.xx.xx; };
version "[bitch-got-denied]";
};
zone "." { type hint; file "/etc/db.cache"; };
zone "mywebsite.com" { type master; file "/var/named/slaves/mywebsite.com.hosts"; allow-update { none; }; }; zone "mysecondwebsite.com" { type master; file "/var/named/slaves/mysecondwebsite.com.hosts"; allow-update { none; };
Lets say I have both Mywebsite.com & Mysecondwebsite.com .hosts files pointing to the same IP. If someone goes to Mywebsite.com or Mysecondwebsite.com it resolves to the same server, the only obvious difference is the name in the URL bar (depending on which FQDN the client uses to navigate to our domain.)
My question and what I need help with is, I want when someone goes to Mysecondwebsite.com that in the URL bar it gets redirected to Mywebsite.com. I know I can use my hosting company to just do a redirect (standard or stealth) through their online interface, but wanted to see if this could be done on our DNS servers. I simply want a standard redirect. Perhaps I need to mess with the Webserver itself... Any feedback on the best way to accomplish this would be greatly appreciated!
Solution 1:
No - an HTTP redirect (the kind that changes the address bar) can never be done in DNS alone; DNS providers who offer this kind of service simply point the name to their own HTTP server and configure the redirect there.
You will need to configure this on your web server - let us know what kind of server it is and we can help you through configuring the redirect.
Edit: To configure your Apache to redirect:
- Add a new site file:
/etc/apache2/sites-available/redirect
-
Give that file these contents:
<VirtualHost *:80> ServerName mysecondwebsite.com Redirect permanent / http://mywebsite.com/ </VirtualHost>
Enable the site:
a2ensite redirect
- Activate the new config by gracefully restarting the Apache service:
service apache2 reload