In some cases, when you might be transferring your websites over to HostGoi from another provider you may want to test the website functionality without making any changes to the domain’s DNS records, i.e without pointing the site to the new server for everyone else on the internet. You can achieve this by editing the hosts file on your computer.
You need to know the new IP address of your web hosting account or server with Host4Geeks. You can usually find this from the order confirmation email/details.
What is the hosts file?
The hosts file is used to map hostnames domain names to an IP Address. With the hosts file you can change the IP address that you resolve a given domain name to. This change only affects your own computer without affecting how the domain is resolved worldwide.
The location of the hosts file, depending on the operating system that you are using, is:
- Windows – SystemRoot > system32 > drivers > etc > hosts
By default the system root is C:\Windows, so if you are using Windows, your hostsfile is most probably: C:\Windows\System32\drivers\etc\hosts)
- Linux – /etc/hosts
- Mac OS X – /private/etc/hosts
Editing your hosts file
- From the Start Menu, search for “Notepad” (Win 8, 10) or navigate to: “All Programs -> Accessories -> Notepad” (Win XP, Vista, 7).
- Right click on Notepad and select “Run As Administrator”.
- In Notepad, click “Open” and select the file
- At the bottom of the file, add your new IP address followed by the domain name: 22.214.171.124 example.com www.example.com
- Save this file overwriting the previous version.
- 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.
- 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 126.96.36.199 and the domain example.com. You will need to add the line: 188.8.131.52 example.com www.example.com
- Save the file. All requests for the domain www.example.com and example.com will direct to the specified IP (184.108.40.206).
You should be logged in with a user with administrator privileges on your MAC.
- Open Applications -> Utilities ->Terminal.
- Edit the hosts file with a command line text editor such as nano by typing the following line in the terminal (the command will require your Mac user’s password): sudo nano /private/etc/hosts
- Add your changes at the bottom of the file as shown previously.
- Save the changes with the Control and X key combination.
Testing your Changes
Pinging the domain name is the easiest way to test if the newly configured IP is working.
To test that the domain is pointed to the correct IP in your hosts file, type the following:
PING www.example.com (192.168.0.1) 56(84) bytes of data. 64 bytes from www.example.com (192.168.0.1): icmp_req=1 ttl=58 time=1.40 ms 64 bytes from www.example.com (192.168.0.1): icmp_req=2 ttl=58 time=1.31 ms 64 bytes from www.example.com (192.168.0.1): icmp_req=3 ttl=58 time=1.36 ms 64 bytes from www.example.com (192.168.0.1): icmp_req=4 ttl=58 time=1.36 ms
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.