The hosts file on your computer allows you to override DNS and manually map hostnames (domains) to IP addresses. This can come in handy during migrations as you might want to see how the website looks on a different server, but perhaps DNS hasn’t been pointed to the new server or propagated yet. Modifying your hosts file causes your local machine to look directly at the Internet Protocol (IP) address that you specify. This involves adding two entries to it. Each entry contains the IP address to which you want the site to resolve and a version of the Internet address.
Now let’s look at accessing the hosts files in the different operating systems…
Step 1: Open Notepad as an Administrator
You’ll need administrator privileges for this operation.
- Click the Windows button and type “notepad” Let the search feature find the Notepad application.
- Right-click the Notepad app, then click Run as administrator
- Windows User Account Control should pop up asking, “Do you want to allow this app to make changes to your device?” Click Yes
Step 2: Open the Windows Hosts File
- In Notepad, click File > Open
- Navigate to c:\windows\system32\drivers\etc
- In the lower-right corner, just above the Open button, click the drop-down menu to change the file type to All Files
- Select “hosts” and click Open
Step 3: Edit the File
Add the IP address and host name in the following format where 0.0.0.0 is the IP of the server where the website is hosted…
Once you’re finished making your changes, save the file ( File > Save ) and exit.
If you make an edit to the hosts file and something stops working, you can tell Windows to ignore any line by putting a # sign at the beginning of that line.
To access the hosts file in Windows 7 you can use the following command in the Run Line to open notepad and the file.
Once Notepad is open you can edit the file per the above instructions.
Step 1: Open the Mac Terminal
Open the Finder , and go to Applications > Utilities > Terminal
Type the following in the terminal window…
sudo nano /private/etc/hosts
The system will prompt you to enter your password – this is the same password you use to log in to the system. Type it in, and hit Enter .
Step 2: Edit Mac Hosts File
The IP address is first, and the server name comes second. Comments are indicated with a ‘#’ sign.
Enter the IP address you want to refer to first, hit tab, and then the server name (or domain name) that you want to associate with it.
Save your changes by pressing Control + O , then exit by pressing Control + X .