Jump to content
Sign in to follow this  

Wildcard in DNS & Apache

Recommended Posts

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


                       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
www                             CNAME   domain.com.


Now I add the following to the end of the zone file for the wildcard


*.domain.com.             IN      A


Now reload named.


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


[root@web1 named]# host bla.domain.com
bla.domain.com has address
[root@web1 named]# host jy.rules.domain.com
jy.rules.domain.com has address
[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


DocumentRoot /var/www/html
ServerAlias *.domain.com
ServerName www.domain.com


That is very simplified.. so you can always add more entries if needed like the logs or such. Now just restart apache


service httpd restart


Now you should be able to enter ww.domain.com into your browser and it should take you to your website.

Share this post

Link to post
Share on other sites
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...