ShopSite Knowledgebase



setting up 'hosts' file to access new server via domain name before DNS changes

Product: ALL
Version: ALL
Platform: ALL

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
c:\windows

* Windows NT/2000/XP Pro
c:\winnt\system32\drivers\etc

* Windows 10/8/7/Vista/XP Home
c:\windows\system32\drivers\etc

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:

123.456.78.9 www.mydomain.com

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:

http://maximumpcguides.com/windows-vista/edit-the-windows-vista-hosts-file/


Mac OS X 'hosts' file resources:

http://support.apple.com/kb/TA27291?viewlocale=en_US


Related Articles

No related articles were found.

Attachments

No attachments were found.

Visitor Comments

Article Details

Last Updated
5th of December, 2008

Would you like to...

Print this page  Print this page

Email this page  Email this page

Post a comment  Post a comment

 Subscribe me

Subscribe me  Remove from favorites

Remove Highlighting Remove Highlighting

Edit this Article

Quick Edit

Export to PDF


User Opinions



How would you rate this answer?




Thank you for rating this answer.

Continue