Hosts file entries used to resolve hosts names before DNS. Adding host entries to your local PC ‘s hosts file which will allow you to see the domain hosted from the server IP that you added in the hosts file.
Modifying your hosts file will allow you to override the DNS for a domain, on that particular machine. This can be used to test your site without changing the DNS. If you add host entry, machine only to look directly at the IP specified in the host file.
Your hosts file will need to have two entries added that will contain the IP address you want the site to resolve to and the address.
IP domain.com www.domain.com
Example
77.235.XX.XX domain.com www.domain.com
Windows OS
C:\WINDOWS\system32\drivers\etc\hosts
- Go to Start > run Notepad.
- Right click on the Notepad icon and select “Run as administrator.”
- Select Open from the File menu option.
- In the File name field, enter the following path: c:\Windows\System32\drivers\etc\hosts
- Add the hostname/domain name and IP address to the bottom of the host file.
For example:
77.235.XX.XX example.com www.example.com
Once the proper domain information is added you will save the file and your system will begin resolving to the specified IP.
Linux Operating Systems
Hosts file location : /etc/hosts
- Open a Terminal window.
- Open the hosts file in a text editor – you can use vi command or a different one you have available to open up the hosts file
vi /etc/hosts
- Add the destination server’s IP address and domain name under the latest entry in the file.
For example:
77.235.XX.XX example.com www.example.com
- Save the host file.
- Reload your browser for the changes to take effect.
MacOS X
Hosts file location : /private/etc/hosts
- Open a Finder window.
- Select Applications from the sidebar.
- Double-click on Utilities.
- Double-click Terminal.
- Type sudo nano /etc/hosts
sudo nano /etc/hosts
- Enter your administrator password
- Add hosts entry with your server IP and domain name.
For example:
77.235.XX.XX example.com www.example.com
- Once you’re done, hold down the control and O keys to save the file, then control and X to exit.
Note: You need to run a ping test to ensure that it shows the correct IP. Once testing is finished these entries should be removed.