DescriptionTesting a website by adding it to the hosts file
In many cases you might be transferring a website from another hosting platform to one of the LeaseWeb's web hosting servers. This page provides you instructions on how you can test the website functionality without making any changes to the domain's DNS records. You need to know the new IP address of the web hosting server. You can usually find this from the order confirmation email/details.
The hosts file is one of the several system facilities that assists in addressing network nodes in a computer network. It is a common part of an operating system's Internet Protocol (IP) implementation, and serves the function of translating hostnames into numeric protocol addresses, called IP addresses, that identify and locate a host in an IP network.
In some operating systems, the contents of the hosts file is used preferentially to other name resolution methods such as the Domain Name System (DNS), but many systems implement name service switches to provide customization, such as nsswitch.conf for Linux and UNIX. Unlike remote DNS resolvers, the hosts file is under the direct control of the administrator of the local computer.
Editing the hosts file
Most of the Linux distributions use the hosts file at /etc/hosts. You will need root/sudo access to edit this file. Use your favorite editor to open the file. By default it looks something like this:
To add your domain for testing purposes, in the hosts file, you need to specify what domain points to which IP address. In this example, we will use the IP address 192.168.0.1 and the domain example.com. You will need to add the line:
The file should look like this after editing:
Save the file. All requests for the domain www.example.com and example.com will direct to the specified IP (192.168.0.1).
In Windows XP and higher versions, the hosts file is located in %SystemRoot%\system32\drivers\etc\hosts, where %SystemRoot% is the directory where Windows has been installed. By default, this should be C:\Windows\System32\drivers\etc\hosts. You can edit the file with notepad, but in most cases you will have to do this as an admin user. To do this:
- Click the Start menu.
- Select All Programs.
- Select Accessories.
- Right-click on Notepad and select Run as administrator.
- Browse to the following path: %SystemRoot%\system32\drivers\etc\ (or as by default C:\Windows\System32\drivers\etc\).
- You will need to choose that instead of showing Text Documents (*.txt) you will see all files in the directory.
- Open the hosts file.
By default, there should be no entries. You can add new entries after the comment lines that starts with #. After editing, the file should look like this:
In Mac OS X
Mac OS X stores the hosts file at /etc/private/hosts. Easiest way to edit this is from the Terminal. You can do this either by typing "Terminal" into Spotlight or by opening Finder and navigating to Applications > Utilities > Terminal. To open the hosts file for editing, type:
The file itself should look the same as in Linux or any other *nix system. You can add the the new IP for the domain:
Testing the hosts file
Pinging the domain name is the easiest way to test if the newly configured IP is working. Tools like dig, nslookup, and host use the DNS data to retrieve information - because of this you don't see the changes in effect.
To test that the domain is pointed to the correct IP in your hosts file, type the following:
The response should come from the newly configured IP:
In Linux or Mac OS X, you can use ping from the Shell or Terminal respectively. In Windows, you will need to open the command line: Press CTRL + Windows button on the keyboard. In the pop-up window, type cmd and hit enter.