5

We'd like to set things up on our developers' Windows boxes such that all .dev domains resolve to localhost. On Unix systems, firing up dnsmasq with a single additional line to hosts would do it, but dnsmasq is sadly Unix-only. On the Windows side, I'm not aware of an equivalent solution, either built-in or available in a third-party utility. The best I've been able to come up with are some PowerShell scripts, running as administrator, that would alter c:\Windows\System32\Drivers\etc\hosts directly—ugly and error-prone at best.

What's the right way to do this? Does no solution meaningfully exist right now?

Benjamin Pollack
  • 235
  • 1
  • 2
  • 6
  • I don't think the hosts files in Windows supports wildcards. You could do what TheFiddlerWins is suggesting and set a wildcard A record to 127.0.0.1, but yes it would go to all Windows clients using that DNS server. Probably doesn't matter since it is a .dev though. But mixing "production" and "development" is typically taboo. Why the need? Can't the dev peeps create their own entries as they build up a local site/server/host? – TheCleaner Sep 17 '13 at 15:58
  • The issue here is that there are a collection of sites (`foo.com`, `bar.com`, etc.) that talk to each other; we'd like to make it so that their location on the dev boxes is similar (`foo.dev`, `bar.dev`), which allows for consistency without editing the hosts file for each site. Making new virtual hosts in IIS would be sufficient. – Benjamin Pollack Sep 17 '13 at 16:06
  • This seems like a duplicate of the following answer: http://stackoverflow.com/questions/138162/wildcards-in-a-windows-hosts-file?answertab=votes#tab-top – Josh Oct 13 '16 at 22:53
  • Everyone, beware - .dev domain is now TLD: https://domains.google/tld/dev/ – Janis Veinbergs Jul 05 '22 at 15:35

4 Answers4

8

Alternative: get your devs to just append .localtest.me, which is a public DNS zone that already exists (with a * A record) for this purpose.

Ross Presser
  • 443
  • 6
  • 21
  • 11
    I'm not sure that adding an untrusted public domain to your workflow is a great plan! – JamesRyan Jan 15 '14 at 23:48
  • If this concerns you, it would be simple to add a DNS test to whatever monitoring solution you use. If the DNS for localtest.me has changed in the last second, make it blast an alert to your devs. – Ross Presser Jan 17 '14 at 16:20
5

I have resolved this situation using Acrylic DNS Proxy. It's a free, open-source software for Windows that allows you to wildcard a folder as local top domain registry.

  1. Download Acrylic DNS Proxy here: http://mayakron.altervista.org/wikibase/show.php?id=AcrylicHome
  2. Configure your Network settings to point to your local IP address as explained here: http://mayakron.altervista.org/wikibase/show.php?id=AcrylicWindows10Configuration
  3. Open your Acrylic config file here: Start > Programs > Acrylic DNS Proxy > Edit Custom Hosts File (AcrylicHosts.txt)
  4. Add your wildcarded top level domain like this: 127.0.0.1 *.dev
  5. Restart Acrylic like this: Start > Programs > Acrylic DNS Proxy > Restart Acrylic Service
  6. Add the wildcard to your Apache config file. It may look similar to this:

It may look similar to this:

LoadModule vhost_alias_module modules/mod_vhost_alias.so  

NameVirtualHost *.dev:80  

<Directory "/www/sites">  
    Options Indexes FollowSymLinks Includes ExecCGI  
    AllowOverride All  
    Order allow,deny  
    Allow from all  
 </Directory>  

 <VirtualHost *.dev:80>  
     VirtualDocumentRoot c:/www/sites/%-1/%-2+/  
 </VirtualHost>  

That should do the trick.

Josh
  • 151
  • 1
  • 3
3

Do you have a .dev zone in DNS already? You can create a wildcard entry where *.dev goes to the loopback.

TheFiddlerWins
  • 2,973
  • 1
  • 14
  • 22
3

I can recommend http://localhost.tv - all subdomains resolve to 127.0.0.1

Esben von Buchwald
  • 251
  • 1
  • 3
  • 9