Enabling Wildcard DNS on CPanel Servers

Thu, Apr 13, 2006

Server, Web

In some cases, you will want a subdomain to be the same as the homepage of a website. For example:

http://www.domain.com
http://sub.domain.com
http://whatever.domain.com
http://something.domain.com
http://anything.domain.com

will all show the same page. Even if you just invented one subdomain up, it will still show the same page, the homepage. Err, hmmm what’s the use of that? Well for some this is totally non-sense, but for some, it totally makes sense why to do this, where you can be having the same file running and just using server-side scripts to change content of a website dynamically. Now if you believe wildcard DNS is something you need to do in order to achieve something like this and is running a CPanel server, how can this be done?

First is, if you just have a shared hosting account and has no access to WHM and no SSH access to the httpd.conf file, you might need to ask permission from the server owner. If you run your own server, or is given the freedom to play around with these files, you can go ahead and follow the procedure.

But I do believe there may also be some other way to do this, maybe with just playing around with the .htaccess file, but tough regex commands and .htaccess modifications are not my cup of tea. Another thing is, I am not guaranteeing anyone that what you will do will not mess up your servers. Although this procedure has served me well, if ever something happens to your server as a result of following this procedure, I, the author, this website, my business, my friends, my cats and my dogs will not be held responsible for what ever losses may occur on your end.

Ok now, how to do it?

  1. Login to WHM
  2. Click on Edit DNS Zone on the side navigation.
  3. Choose the domain to edit, and click on the Edit button.
  4. Under Add New Entries Below this Line add this:
    Domain: *
    TTL: 14400 (this is the default value)
    Record Type: A in (your IP address)
  5. Submit and this will now be added.
  6. Access your httpd.conf file. Login as root, via SSH.
  7. To access the file in a CPanel server go to:
    # cd /etc/httpd/conf/
  8. Use your favorite text editor, or just simply type:
    # pico httpd.conf
  9. Do a find on your domain and you may find something like this:


    ServerAlias yourdomainserver.com
    ServerAdmin webmaster@yourdomainserver.com
    DocumentRoot /home/yourdoma/public_html
    BytesLog domlogs/yourdomainserver.com-bytes_log
    ServerName www.yourdomainserver.com
    User yourdoma
    Group yourdoma
    CustomLog /usr/local/apache/domlogs/yourdomainserver.com combined
    ScriptAlias /cgi-bin/ /home/yourdoma/public_html/cgi-bin/

    On the line:

    ServerAlias yourdomainserver.com

    Change to:

    ServerAlias: *.yourdomainserver.com yourdomainserver.com

  10. Exit or press Ctrl X if using Pico.
  11. Save the file when asked and replace the existing file.
  12. Restart the apache web server by typing in:
    # service httpd restart

Done! You are all set to go. Wildcard DNS Enabled on a CPanel Server

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google

This post was written by:

Benj Arriola - who has written 140 posts on action online.

Started a career as a chemist. Worked in the industry and academe and pursued a master's degree in chemistry. Then one day, here I go, start a computer shop, then web company in 1999, won a few awards and just started a web career working on websites of various companies and making sure the websites work for them.

Contact the author

17 Comments For This Post

  1. pilkster Says:

    Wow, your text size is super small (using IE 6.0) - I’m sure there is some great info here, but I cant read it!

  2. usman aslam Says:

    Hi, Good stuff, just what i was looking for. Help me alot… although the last command

    # service httpd restart

    did not work for me, i just restarted HTTP(Apache) server using WHM

  3. Dallas SEO Says:

    Great concept, I just need to get it to work. Dont have shell access. When I install the file i get a line 1175 action not recognized error.

  4. clear blogs Says:

    Nice, tutorial, thanks usman for the tip.
    httpd restart doesnt work on my system either.. im on freeBSD… you?

  5. Benj Arriola Says:

    Hi Dallas… I think you need SSH, if your host does not allow this, maybe you can find a way using the .htaccess file. But I have not tested anything. Obviously you are into SEO and I guess you will agree by experience that:

    http://keywords.domain.com works better than http://www.domain.com/keywords/

    And having this setup helps a lot in SEO since SEs treat each subdomain as a new website, solves some sandboxing issues and interlinking of pages helps in PR a lot.

  6. Benj Arriola Says:

    # service httpd restart - I believe is a Redhat thing. But if you know the syntax on how to start and start or restart any service, you can use what ever syntax is supposed to have.

    I guess if that does not work, you can use WHM’s restart services. Thanks Usman for the tip to others.

  7. Benj Arriola Says:

    Hi Pilkster, I saw your comment on Greg’s blog and I am happy this post helped you in the subdomain plugin for wordpress. And as for the font, it is not longer as small as it was. Thanks for informing me also, so I made it bigger already.

  8. Dallas SEO Says:

    Well I got it to work for one site. I can take care of the settings via WHM. My provider had to do it for the Apache piece. The crazy thing is we cant get it to work on a second domain of mine with the same ISP. But it works like a charm with the SEs and a blog program. THanks!

  9. Benj Arriola Says:

    Nice to know you got it working. I think you have also been to Greg’s blog. Hehe.

  10. Simon Says:

    If service httpd restart doesn’t work use the following command…

    /etc/rc.d/init.d/httpd restart

    :)

  11. Benj Arriola Says:

    Thanks Simon! :D

  12. RRRRyan Says:

    Now for the tough challenge. Can CPanel be configured to do this by default when a domain is parked?

  13. Benj Arriola Says:

    Hi RRRRyan, it can be done. But I believe it cannot be done by default when a domain is parked. You might need to do the same httpd.conf edits. Try it out and tell us how it goes.

  14. Alan Says:

    Hi

    I cannot get access to the “httpd.conf” on my server.

    I have checked with other hosting companies, including Dreamhost and MediaTemple - neither allow access to the file.

    Dreamhost and my current host recommended I attempt to enable wildcard DNS through the .htaccess file, if anyone knows how to do this, do they have an example or idea how that would work?

    Alan.

  15. Senaia Says:

    Thanks for the information.

    I followed your instructions and seems to work. But im having email problems now, The email simply does not work anymore !

    Any idea’s why the email is affected by this !?

  16. Eligio Says:

    hello benj, I stumble on this post while looking for a way to get a dynamic subdomain. ito pala yon, then all I need is a php code that will catch all the subdomain name. maraming salamat :D

  17. Benj Arriola Says:

    Hehehe, nice research Eli, sa akin din napunta ang sagot. :) Yup just catch with a $_SERVER[HTTP_HOST].

1 Trackbacks For This Post

  1. Trackback Submitter Says:

    Seo Training…

    This comment was submitted automatically using Trackback Submitter. If you would like to submit comments to thousands of blogs yourself (so you may get indexed fast and get thousands of backlinks automatically), please see Trackback Submitter web for m…

Leave a Reply