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 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.
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.