Changing your HOSTS file on Windows XP, Windows Vista, Mac OS X and Linux
During website development you may need to access a site without making changes to the DNS, for example if you wish to start developing a site on a new uk web hosting server without changing the live site. Often you will be able to access the site through a temporary address, but with the way that many of the current Content Management Systems work such as b2evolution, Wordpress, Magento, Drupal, Joomla, Mambo, PHP-Nuke, etc. then access through this temporary address may result in the site displaying incorrectly. There are a few ways around this, but the simplest one is to edit your HOSTS file. What this file does is allow you to define static hostname to IP address mappings in a file which will be given priority over your specified DNS servers when performing hostname lookup’s for hosts that are contained in this file.
The HOSTS file has a very simple format, this is simply the IP address you wish to map to followed by the hostname you are mapping to it. E.g.
85.13.250.34 www.nethosted.co.uk
This format remains the same across operating systems, however the location of the hosts file does vary. Here is where you can find it on different operating systems:
- Windows 95/98/Me: c:\windows\hosts
- Windows NT/2000/XP Pro: c:\winnt\system32\drivers\etc\hosts
- Windows XP Home: c:\windows\system32\drivers\etc\hosts
- Mac OS X: /private/etc/hosts
- Linux: /etc/hosts
On Windows Vista they have unfortunately decided to make things more complicated and less accessible, but it’s still possible to make changes to this. You need to edit the file with administrator rights, to do this in Vista:
- Start Menu -> All Programs -> Accessories
- Right click “Notepad” and choose “Run as administrator”
- Click “Continue” on the security prompt
- Select File -> Open
- Browse to “C:\Windows\System32\Drivers\etc”
- Change the file filter selection from “Text Documents (*.txt)” to “All Files (*.*)”
- Select the “hosts” file and “Open”
- Make the changes that you require and save the file.
For OS X or Linux you should edit this file with your favourite text editor from the root account.
Using this method can save you a lot of headaches in the site development process, and offers you the flexibility to develop your site from anywhere without having to mess about with changing the DNS servers on your web hosting. It also removes the need to consider DNS caching and propagation. This method works for any kind of hosting you have, be it linux hosting, reseller hosting or even VPS hosting.
Tags: hosts, hosts file, web development, windows vista, windows xp

Client Support








December 4th, 2008 at 3:23 pm
The hyphen in the example hosts entry above is not part of the spec, though it may still work OK. Normally a hosts entry will look like:
85.13.250.34 http://www.nethosted.co.uk
Also there’s nothing in a default Drupal installation that stops it from working at an alternate URL. In fact it’s specifically designed to allow this. However it is true that any website may display incorrectly if links and references to other assets are not set up correctly.
December 15th, 2008 at 3:32 pm
Giles,
Thanks for your comments, the hyphen was indeed a mistake so thanks for pointing that out it’s been corrected now.
With the CMS systems that’s fair enough, these weren’t all tested but I know some CMS have problems with accessing via a temporary URL, I’ve changed the wording to indicate that this may cause issues but may not.
Cheers!