How should I set up a server to map all subdomains of a domain to an IP?

I wish I could do something like that in the hosts file:

127.0.0.1 *.example.com
link|improve this question

4  
Not in hosts but in your DNS server. – mailq Dec 21 '11 at 21:13
All subdomains of parent domain or hosts unside domain? They are very different things – Lazy Badger Dec 22 '11 at 4:58
feedback

1 Answer

up vote 5 down vote accepted

As mailq mentioned, DNS supports wildcard host entries (while the hosts file does not).

A DNS record with the name * will match all names for which there is no other record on that name, returning the wildcard record.

An entry would look like this:

*    IN    A    192.0.2.1

But, I'm not sure why you'd want to do that pointing to 127.0.0.1 - can you clarify what you're attempting to accomplish with this, and we might be able to point you in a better direction?

link|improve this answer
CNAME works for hosts, not subdomains as OP asked – Lazy Badger Dec 22 '11 at 5:00
@LazyBadger Huh? Who said anything about a CNAME? – Shane Madden Dec 22 '11 at 6:09
mea culpa, think and write in parallel. Wildcard RR haven't relation to CNAME, shure – Lazy Badger Dec 22 '11 at 6:42
feedback

Your Answer

 
or
required, but never shown

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