What is the "hosts" file?
The hosts file is a computer file used by an operating system to map hostnames to IP addresses. The hosts file is a plain text file
The hosts file is one of several system facilities that assists in addressing network nodes in a computer network. It is a common part of an operating system's Internet Protocol (IP) implementation, and serves the function of translating human-friendly hostnames into numeric protocol addresses, called IP addresses, that identify and locate a host in an IP network.
Where is the "hosts" file located?
Windows Vista and Windows 7
Vista and Windows 7 use User Account Control (UAC) so Notepad must be run as Administrator.
- 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:
sudo nano /etc/hosts
Mac OS X 10.0 - 10.1.5
- Open /Applications/Utilities/NetInfo Manager.
- To allow editing the NetInfo database, click the padlock in the lower left corner of the window.
- Enter your password and click OK.
- In the second column of the browser view, select the node named machines. You will see entries for -DHCP-, broadcasthost, and localhost in the third column.
- Select the localhost item in the third column.
- Choose Duplicate from the Edit menu (the quickest way to create a new entry is to duplicate an existing one). A confirmation alert appears.
- Click Duplicate. A new entry called localhost copy appears, and its properties are shown below the browser view.
- Double-click the value of the ip_address property and enter the IP address of the other computer.
- Double-click the value of the name property and enter the hostname you want for the other computer.
- Click the serves property and choose Delete from the Edit menu.
- Choose Save from the File menu. A confirmation alert appears.
- Click Update this copy.
- Repeat steps 6 through 12 for each additional host entry you wish to add.
- Choose Quit from the NetInfo Manager menu. You do not need to restart the computer.
Mac OS X 10.6 - 10.1.8
- Open Applications > Utilities > Terminal.
- Open the hosts file by typing the following in the Terminal window:
sudo nano /private/etc/hosts
- 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.
- Save the hosts file by pressing Control+x and answering y.
- Make your changes take effect by flushing the DNS cache with the following command:
How to edit records in the "hosts" file.
Once you are in your text editor you can edit the file. In this example we will block Facebook. To do this just enter in the following after the # mark ( on a new line )
0.0.0.0 facebook.com 0.0.0.0 www.facebook.com
To test an IP address that does not have the DNS for the domain pointing to it yet.
22.214.171.124 domain.com 126.96.36.199 www.domain.com