Using a hosts file entry on your laptop or computer allows you to force your browser to a specific web server, this is helpful when you are waiting for dns updates on a domain name to complete or your have recently transferred or registered a domain name,
Using your HOSTS file for website previews.
- If you are not using your actual domain name in the website URL certain website features may not work correctly.
- Wordpress websites may force a rewrite on the domain name URL so it may not display or may point back to the previous host.
- Visiting the site via HTTPS will only work with the exact domain name.
To test your website with your own domain name (temporary URL) before DNS propagation has completed, you can use your local computer's HOSTS file. Your computer will read this HOSTS file before it looks up the DNS for your domain. Below you will find instructions for editing the HOSTS file on Windows Apple's Mac OS X.
Windows.
- Locate the HOSTS file on your computer. This is usually located in C:\windows\system32\drivers\etc\hosts
- Open this file with a text editor such as Notepad++ or Notepad
- Open the file, you will see two columns of information, the first containing IP addresses and the second containing host names. By default, a windows hosts file should be similar to the following:
Filename: hosts
127.0.0.1 localhost - You can add additional lines to this file that will point requests for a particular domain to your new server's IP address. Example:
Filename: hosts
127.0.0.1 localhost
50.321.123.80 example.com
50.321.123.80 www.example.com - Save your changes.
- Restart any currently open browsers.
- You may also want to flush your DNS cache. To do this go to Start, and then Run, then type "cmd" and hit enter. Type the following:
ipconfig /flushdns - Visit your new site using http://example.com or http://www.example.com/
Mac OS X.
- In Applications, open Terminal, then the Utilities folder.
-
Type the following command to edit your hosts file:
sudo vi /private/etc/hosts - When prompted, enter your user password.
- You will see a file with contents similar to the following:
Filename: hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
Add your domain and IP address to the bottom of the file. For example:
Filename: hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
50.321.123.80 example.com
50.321.123.80 www.example.com - Press "i" to enter "insert mode" so you can edit the file.
- Press "Esc" to exit "insert mode" when you are done modifying the file.
- Type ":wq" to save and quit.
- Restart any currently open browsers.
Visit your new site using http://example.com/ or http://www.example.com/