20

I have a lot of subdomains in the main domain xxx.zzz

So, for this domain, I can have

aaa.xxx.zzz
bbb.xxx.zzz
ccc.xxx.zzz
ddd.xxx.zzz
eee.xxx.zzz

....ETC....

Istead of adding each subdomain in the host file, I would like to add only the main domain xxx.zzz and then to be able to access all the subdomains.

I have tryed with *.xxx.zzz but apparently, this will not work (Linux or Windows).

Any idea is welcome. Thank you very much.

Milos Cuculovic
  • 401
  • 2
  • 8
  • 21
  • 1
    In short: you should use a DNS. Setup and internal DNS server and add those subdomains. – eldblz Dec 18 '12 at 08:01
  • @eldblz, thank you. In fact, I am using a DNS on the server sidde but how to add only the main domain in the dns file, not all the subdomains? – Milos Cuculovic Dec 18 '12 at 08:08

3 Answers3

24

Wildcards don't work in hosts files. You either have to write them all:

w.x.y.z example.com foo.example.com bar.example.com baz.example.com

or setup proper DNS

ptman
  • 27,124
  • 2
  • 26
  • 45
5

If you REALLY want this to work you should be using DNS as stated but if you're not in control of DNS and need to use the HOSTS file, you can use a DNS Proxy on your PC which allows wildcards in its own HOSTS file.

Example is in this thread, read down to the post about Acrilic DNS : https://stackoverflow.com/questions/138162/wildcards-in-a-hosts-file

user72593
  • 423
  • 2
  • 6
  • 14
5

Wildcard syntax is possible in full-featured DNS servers. For BIND record should look like this:

host1.example.com. 3600 IN  A     127.0.0.2
*.example.com.     3600 IN  CNAME host1.example.com.

If you clarify what DNS server you use I can provide an example for it.

DukeLion
  • 3,239
  • 1
  • 17
  • 19