2005-02-25, 01:56 PM
Here is a nice idea for people that have like webhosting or just run any websites with subdomains. Also i often type a url like ww.domain.com.
So a wildcard will catch any not matched dns entry and point it to a IP. Say I have this simple dns zone file
Code:
NS ns1.domain.com.
NS ns2.domain.com.
NS ns3.domain.com.
domain.com. MX 5 flood.domain.com.
domain.com. MX 20 web2.domain.com.
domain.com. A 66.111.22.33
www CNAME domain.com.
Now I add the following to the end of the zone file for the wildcard
Code:
*.domain.com. IN A 66.111.22.33
Now reload named.
Code:
service named reload
So that will take all random subdomains people may try and then send them to the IP of my webserver for example. We can easily test that
Code:
[root@web1 named]# host bla.domain.com
bla.domain.com has address 66.111.22.33
[root@web1 named]# host jy.rules.domain.com
jy.rules.domain.com has address 66.111.22.33
[root@web1 named]# host AHHHHHHHHH.domain.com
AHHHHHHHHH.domain.com has address 666.111.22.33
So now that bind is all setup we need to do the same for apache. You need to have your virtualhosting setup in apache for this to work
So we add the following simple section at the bottom of the httpd.conf file
Code:
<VirtualHost 66.111.22.33>
DocumentRoot /var/www/html
ServerAlias *.domain.com
ServerName www.domain.com
</VirtualHost>
That is very simplified.. so you can always add more entries if needed like the logs or such. Now just restart apache
Code:
service httpd restart
Now you should be able to enter ww.domain.com into your browser and it should take you to your website.