The Complete Guide To Hosts Files

All computing machines have a computer name and an IP address on a Windows network. The computer name is also called the hostname.

What Are Hosts Files?

The hosts file is a plain-text file that contains a list of hostnames and their corresponding IP addresses.

According to Techopedia, as the popularity of the Internet increased, the need emerged to gather all the information about the different hosts in a network in a convenient place. Thus, hosts files came into being.

Why And Where Are Hosts Files Needed?

Hosts files are used to override the DNS system for testing purposes so that a Web browser or other application can be redirected to a specific IP address. Also, an IP address in a hosts file can retrieve a website more quickly.

The hosts file is still used in computer systems like Windows, Linux, Mac etc. and can be very useful for testing purposes.

Finding And Editing Hosts Files in Mac:

On Mac computers, hosts files are in the /private/etc. Folder. If you are using the current macOS X 10.6 through 10.12 version:

  1. Select Applications > Utilities > Terminal to open a Terminal window on your computer.
  2. Enter the following command in the Terminal window to open the hosts file: sudo nano/private/etc/hosts
  3. When you are prompted, enter your domain user password.
  4. Edit the hosts file.
  5. The file contains comments and Default hostname mappings. Add your new mappings.
  6. To save the hosts file, press Control+X.
  7. When asked if you want to save your changes, enter y.
  8. To force your changes to take effect, flush the DNS cache by entering the following command: dscacheutil –flushcache

To know more about finding and modifying hosts files on Mac, click setapp.com.

Editing Hosts Files In Older Versions of Mac:

If you are using the older version of Mac, like macOS X 10.0 through 10.1.5, to find and edit your host files:

  1. Open/Applications/Utilities/NetInfo Manager.
  2. To enable editing of the NetInfo, click the padlock icon in the lower-left corner of the window.
  3. Enter your domain user password and select OK.
  4. Select the node named machines in the second column of the browser view.
  5. In the third column, select the entry named localhost.
  6. From the Edit menu, select Duplicate.
  7. A confirmation alert will appear.
  8. Click Duplicate.
  9. A new localhost copy will appear and display its properties below the browser view.
  10. Double-click the value of the ip_address property and enter the IP address of the other computer.
  11. Double-click the name property value and enter the hostname that you want to use for the other computer.
  12. Click the serving property and select Delete from the Edit menu.
  13. From the File menu, select Save.
  14. A confirmation alert will appear.
  15. Click Update this copy.
  16. Repeat steps 6 through 15 for each additional host entry that you want to add.
  17. From the NetInfo Manager menu, select Quit.
  18. You do not need to restart your Mac.

Finding And Editing Hosts Files On Windows

In Windows, the HOSTS file is in the \windows\system32\drivers\etc folder.

Use the following instructions if you’re running Windows 10 or Windows 8:

  1. Press the Windows key.
  2. Type Notepad in the search field.
  3. In the search results, right-click the notepad.
  4. Select Run as administrator.
  5. From notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  6. Make the necessary changes to the file.
  7. Select file> Save to save your changes.

Windows 7 and Windows Vista users follow the instructions listed below:

  1. Select Start > All Programs > Accessories.
  2. Right-click Notepad
  3. Select Run as administrator.
  4. The Windows needs your permission UAC window will appear.
  5. Click Continue to grant permission.
  6. The notepad will open.
  7. In the notepad, select file> Open.
  8. In the File name field, enter the following path: C:\Windows\System32\Drivers\etc\hosts
  9. Select Open.
  10. Make the necessary changes to the file.
  11. Select file> Save to save your changes.

The following instructions are necessary to find and edit hosts files in Windows NT, Windows 2000, and Windows XP users:

  1. Select Start > All Programs > Accessories > Notepad.
  2. Select File > Open.
  3. In the File name field, enter C:\Windows\System32\Drivers\etc\hosts.
  4. Select Open.
  5. Make the necessary changes to the file.
  6. Select file> Save to save your changes.

Finding And Editing Hosts Files On Linux

Use the following instructions if you’re running Linux:

  1. Open a Terminal window.
  2. Enter the following command to open the hosts file in a text editor: sudo nano /etc/hosts.
  3. Enter your domain user password.
  4. Make the necessary changes to the file.
  5. Press Control-X.
  6. When asked if you want to save your changes, enter y.

Conclusion

In regular day-to-day use of your device, you will not need to edit the hosts files, but you should know how to find and modify them if the need arises. The instructions mentioned above will help you do that no matter what operating system you use.