A host file compiles hosts in an operating system file that can be used to map a connection between an IP address and domain names. Host file is checked before DNS, if you place an entry in the file will supersede anything set in DNS. This feature is useful in testing your website as this allows you to control which IP your local computer will visit regardless of what is set in DNS.
The host file syntax is simple, each line has an IP address and a domain name separated by one or more space. By default, host files contain entries for “localhost” as well as some comment text describing the file and its use.
1. From the Start Menu, search for Notepad (Win 8, 10) or navigate to: All Programs -> Accessories -> Notepad (Win XP, Vista, 7).
2. Right click on Notepad and select Run As Administrator.
3. In Notepad, click Open and select the file C:\Windows\System32\Drivers\etc\hosts
4. Edit file and Save.
1. Go to your Programs and open Terminal.
2. Copy the following command and paste it in Terminal. Confirm with Enter to execute it.
|sudo nano /etc/hosts|
|Note: You may then have to enter the password for your computer.|
3. Adjust the hosts file. Enter the IP address of your hosting package, followed by your subdomain names (always with a space between them). An example with yourdomain.com:
|184.108.40.206 yourdomain.com www.yourdomain.com|
|Note: Change yourdomain.com to your website name or names.|
4. Add this line at the bottom of the file.
5. Save the host file by entering CTRL + O.
6. The system will ask you to choose a name for your file. Do not change the name and press Enter.
7. Close with CTRL + X.
8. Restart your Mac computer.