I need to test sub-domains on my localhost. How can I effectively have this result of adding *.localhost.com to m /etc/hosts/ file?

If it's not possible, how do I work around this problem? I need to test wildcard sub-domains on my localserver. It is a Django dev server, can the django dev server handle the sub-domains? Can some other piece of software/routing give me the end result I want?

link|improve this question

76% accept rate
Belongs on superuser ? – Paul R Mar 2 '10 at 16:48
I know people say it's not possible! But how do I do it anyway! What is something outside of /etc/hosts/ I can use to get the effect. I'm testing a development server. – MikeN Mar 2 '10 at 20:17
feedback

migrated from stackoverflow.com Mar 2 '10 at 17:06

This question came from our site for professional and enthusiast programmers.

8 Answers

up vote 10 down vote accepted

I have written a dns proxy in Python. It will read wildcard entries in /etc/hosts. See here: http://code.google.com/p/marlon-tools/source/browse/tools/dnsproxy/dnsproxy.py

link|improve this answer
Thanks! This is exactly what I needed! Works great! – MikeN May 17 '11 at 20:06
feedback

It is not possible to specify wildcards in the /etc/hosts file. Either specify the required hostnames explicitly or alternatively set up a local name server with the appropriate rules.

link|improve this answer
feedback

Install dnsmasq (I do this on all my Linux desktops as a DNS cache anyways). In dnsmasq.conf add the line "address=/localhost.com/127.0.0.1". Done.

link|improve this answer
Thank you! I've been wanting this for years. It works wonderfully. Now I don't have to edit /etc/hosts every time I make a new website to test locally. – JasonWoof Oct 9 '10 at 22:30
dnsmasq.conf didn't exist by default. I created the file /etc/dnsmasq.conf and added just that line and started $sudo dnsmasq. The browsers picked up the changes without restart. – so_mv Sep 13 '11 at 7:58
1  
Brilliant! Note for Mac users, it really is this simple: 1. sudo port install dnsmasq 2. edit /opt/local/etc/dnsmasq.conf 3. sudo port load dnsmasq – tomc Nov 16 '11 at 11:57
feedback

You need to set up a DNS server and have each client use it for resolution. The server itself can be something as "light" as dnsmasq or as heavy as BIND.

link|improve this answer
+1 for dnsmasq, which is really well-documented and easy to use – David Schmitt May 2 '11 at 12:24
feedback

You cannot use a wildcard in /etc/hosts. Have a look here for a good walkthrough on how to accomplish this using Apache: http://postpostmodern.com/instructional/a-smarter-mamp/

link|improve this answer
2  
Apache has nothing to do with subdomains. – Anonymous Mar 2 '10 at 17:55
feedback

The short answer is you don't. The longer answer is you need to be clearer on what you desire to actually achieve, because there is perhaps either a better way, and a different way to achieve it.

For web-hosting (I've never seen it used otherwise) is done in DNS in combination with a virtual hosting aware web server. For more information on wildcard DNS records (Wikipedia), and an article Wildcard hosting with Apache and Bind for Linux using bind and Apache.

At worst, you could use a local DNS server I suppose.

link|improve this answer
feedback

Short answer:

Your /etc/hosts/ file won't let you use wildcards or port numbers. You will need to create one entry for each of your subdomain

link|improve this answer
What would let you specify port numbers? Not DNS AFAIK. – ptman Mar 3 '10 at 11:45
feedback

This DNS based solution worked perfectly in my case, without need to install anything : http://renebakx.nl/7/running-a-local-wildcard-dns-server-on-your-mac/ (Mac OSX 10.7)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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