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 the test link, prior to going live with SSL, verify an alias site works prior to DNS changes, or for other DNS related reasons. This causes your local machine only to look directly at the IP specified.
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. Adding the below two lines for example will point www.domain.com and domain.com to our current PHP5-ITK ("Refreshed" PHP5) cluster:
64.49.219.194 www.domain.com 64.49.219.194 domain.com
Below is how to locate and edit the hosts file on several OS platforms. Once the proper domain information is added you will save the file and your system will begin resolving to the specified IP. Once testing is finished these entries should be removed.
Windows 10, Windows 8, Windows 7 and Windows Vista
Windows 8, Windows 7 and Windows Vista use User Account Control (UAC), so Notepad must be run as Administrator.
For Windows 10 and Windows 8
- Press the Windows key.
- Type Notepad in the search field.
- In the search right click Notepad and select Run as administrator.
- In Notepad, open the following file:
c:\Windows\System32\Drivers\etc\hosts - Make the necessary changes to the hosts file.
- Click File -> Save to save your changes.
For Windows 7 and Windows Vista
- Click Start -> All Programs -> Accessories.
- Right click Notepad and select Run as administrator.
- Click Continue on the "Windows needs your permission" UAC window.
- When Notepad opens Click File -> Open.
- In the filename field type:
C:\Windows\System32\Drivers\etc\hosts - Click Open.
- Make the necessary changes to the hosts file.
- Click File -> Save to save your changes.
Linux
1. Open a terminal window.
2. Open the hosts file in a text editor (you can substitute any text editor):
sudo nano /etc/hosts
3. Enter your password.
4. Make the necessary changes to the hosts file.
5. Press control-X (hold control and hit X), then answer y when asked if you want to save your changes.
Mac OS X 10.1.8 - 10.15
1. Open Applications > Utilities > Terminal.
2. Open the hosts file by typing the following in the Terminal window:
sudo nano /private/etc/hosts
Type your user password when prompted.
3. Edit the hosts file. The hosts file contains some comments (lines starting with the #
symbol), as well as some default hostname mappings (e.g. 127.0.0.1 – local host). Append your new mappings underneath the default mappings.
4. Save the hosts file by pressing Control+x and answering y.
5. Make your changes take effect by flushing the DNS cache with the following command:
dscacheutil -flushcache
for Mojave version (10.14) type: sudo killall -HUP mDNSResponder
6. New mappings should now take effect.