Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As I'm always creating mini test and developmet sites I'm writing a mini-web based script in php 5.3 to ease the creation of local dev sites on windows running a wamp stack which is intended to create a vhost entry and also an entry for the site in the Windows host file and thought I might as well make it as non-windows version specific as possible. It occured to me that:-

a) I can't even remeber a time when my hosts file didn't have more than just a localhost entry and that if it even had that when "out of the box"

b) Have all versions of post Windows 3.1 always used a host file for local DNS queires and is it always located in :\WINDOWS\system32\drivers\etc\hosts ?

I know it sounds a bit lazy to save myself manually doing a couple of easy edits in apache conf and the host file, but I am planning to add a few extra bits to it (creation of a mysql/sqllite/mssql/postgre template database, ability to build a zend framework template etc, so it's not just the vhost and host file entries! I'll also be creating a parallel set-up script to hopefully ease deployment on my Unix vps as well, but that should be a little easier)

share|improve this question

migrated from Jul 25 '12 at 12:16

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

I did a similar thing with powershell, if it is any use to you. I couldn't get over the encoding problem though and ended up doing it in PHP. Windows 7 does honour the hosts file btw, I run a WAMP stack with vhosts for my development. – vascowhite Jul 25 '12 at 9:23
up vote 1 down vote accepted

Do (did) all versions of Windows ship with a host file and do they all have a localhost entry

No. Starting in Windows 7 the localhost entry has been removed. localhost is now resolved in the DNS resolver itself. The file itself is there, but out-of-box it's just a bunch of comments.

That said; Windows 7 behaves like there is a localhost entry in the HOSTS file. localhost does point to and ::1, just with different means.

Have all versions of post Windows 3.1 always used a host file for local DNS queires and is it always located in :\WINDOWS\system32\drivers\etc\hosts

It's always been %WINDIR%\system32\drivers\etc\hosts for NT based Windows. Some versions of Windows, like 2000; use \WINNT instead of \Windows. And as I stated above; Windows 7 doesn't use the HOSTS file at all to resolve localhost.

For non-NT Windows (think 95/98/ME), it's been %Windir%\HOSTS.

share|improve this answer
Cheers, that's a good start point & reminded me I hadn't even considered ipv6 - oops! is there an api to hit the DNS Resolver with an entry? - I'm still pre Win 7 myself so will look further into future proofing the script. FWIW i'm going to try and make the script both web form & cli so the %WINDIR% example should be useful too rather than trying various possible paths to host file – GrundaGrundaGrunda Jan 20 '12 at 22:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .