KB Home

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.

  1. Click Start -> All Programs -> Accessories.
  2. Right click Notepad and select Run as administrator.
  3. Click Continue on the "Windows needs your permission" UAC window.
  4. When Notepad opens Click File -> Open.
  5. In the filename field type:


sudo nano /etc/hosts

Mac OS X 10.0 - 10.1.5

  1. Open /Applications/Utilities/NetInfo Manager.
  2. To allow editing the NetInfo database, click the padlock in the lower left corner of the window.
  3. Enter your password and click OK.
  4. 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.
  5. Select the localhost item in the third column.
  6. Choose Duplicate from the Edit menu (the quickest way to create a new entry is to duplicate an existing one). A confirmation alert appears.
  7. Click Duplicate. A new entry called localhost copy appears, and its properties are shown below the browser view.
  8. Double-click the value of the ip_address property and enter the IP address of the other computer.
  9. Double-click the value of the name property and enter the hostname you want for the other computer.
  10. Click the serves property and choose Delete from the Edit menu.
  11. Choose Save from the File menu. A confirmation alert appears.
  12. Click Update this copy.
  13. Repeat steps 6 through 12 for each additional host entry you wish to add.
  14. Choose Quit from the NetInfo Manager menu. You do not need to restart the computer.

Mac OS X 10.6 - 10.1.8

  1. Open Applications > Utilities > Terminal.
  2. Open the hosts file by typing the following in the Terminal window:
    sudo nano /private/etc/hosts
  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. 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

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 )    facebook.com    www.facebook.com

To test an IP address that does not have the DNS for the domain pointing to it yet. domain.com www.domain.com