setting up 'hosts' file to access new server via domain name before DNS changes
I am setting up a new site or moving an existing site to a new server, and I would like to test the new site before the DNS is setup to point my domain name to this new server. How can I do this?
Solution ID: S5485
Some new sites can be accessed via IP address, but if your new site is sharing an IP address with other sites on the same server (AKA name-based virtual hosting), then you probably MUST access it via your domain name in order for the webserver to know which site to present. The following solution will allow you to access your new site via the domain name before the DNS is setup to point the domain name to your new server. This method involves editing a text file on your desktop/notebook computer that your web browser will check for your domain before it uses the regular DNS lookup system. This file is called a 'hosts' file, and this method is supported on most popular desktop operating systems.
For Microsoft Windows-based desktop operating systems (Windows 95, 98, ME, NT4, 2000, XP, 2003, Vista, 7, etc.), the location of the 'hosts' file varies depending on the Windows operating system (OS) used. To determine where your 'hosts' file is located, choose your OS from the list below:
* Windows 95/98/Me
* Windows NT/2000/XP Pro
* Windows 10/8/7/Vista/XP Home
Look for a file named 'hosts' in the appropriate location. You should see a file called 'hosts' or 'hosts.sam' (if you find both, use just 'hosts'). Double-click on the file to open it. You will be prompted to specify the program to use to open this file, choose Notepad.
NOTE: If your computer is using Windows 10, 8, 7 or Vista, you
may need to run Notepad as Administrator first, then use Notepad's File
-> Open dialog to browser to the location of the file to open it and
edit it. Otherwise, simply editing the file in Notepad without running
it as Administrator first may cause the edits to have no effect and/or
not be saved in the file. To run Notepad as Administrator, click on the Windows 'Start' button, click the 'All Programs' link, click the 'Accessories' folder, and when you see the Notepad application under the Accessories list, right click on it and choose the 'Run as administrator' option.
Once the 'hosts' file is opened in Notepad, follow the instructions in the comments at the top of the file to point your domain name to the new IP address. The line you should add to this file should look similar to this:
[your new IP address] [your domain name]
So if your IP is 123.456.78.9 and your domain is www.mydomain.com, then the line would look like this:
You can also add other domains or subdomains that you may also be using for your site to this same line, for example:
123.456.78.9 www.mydomain.com mydomain.com
will also catch any references to your site at just mydomain.com instead of the full www.mydomain.com.
Save the file as 'hosts' with no file extension. If the file was originally hosts.sam, make sure it saves as just plain 'hosts'. It must also be saved to the same directory it was found in.
Close all of your open web browser windows.
Open a new web browser window, and now when you access your domain it should take you to your new server. This only affects the computer whose hosts file you change, it does not affect other computers on the internet. To make the final switch, contact your hosting provider to have them change their DNS entry to point the domain to your new server.
Additional Windows Vista and Windows 7 'hosts' file resources:
Mac OS X 'hosts' file resources:
No related articles were found.
No attachments were found.
5th of December, 2008