Modifying Your Hosts File

by Barry Dysert
(last updated July 20, 2020)

Your Hosts file (introduced in this tip) is an important system file for network communications, but it can easily be modified just like any other text-based file. Before modifying it, though, it's recommended that you make a backup copy of it just in case something goes wrong. You can make a backup any number of ways, but to keep things simple we'll do everything from within Notepad.

  1. Start Notepad. (How you do this depends on the version of Windows you are using.)
  2. Choose File | Open. Notepad displays the Open dialog box.
  3. Use the controls at the left of the dialog box to navigate to the folder C:\Windows\System32\Drivers\etc. You won't see any files listed in the folder.
  4. Use the drop-down list at the bottom-right of the dialog box (just above the Open and Cancel buttons) to choose All Files (*.*). You should now see files listed in the folder.
  5. Click once on the hosts file.
  6. Click Open. Notepad opens the file.
  7. Choose File | Save As. Notepad displays the Save As dialog box.
  8. Change the File Name box to reflect the file name "hosts backup" without the quote marks.
  9. Click Save. Notepad saves the backup file.

Now make whatever edits you choose to the file, but don't save anything yet. When you've made all the changes you need and you are content with your changes, follow these steps:

  1. Choose File | Save As. Notepad displays the Save As dialog box.
  2. Using the Save As Type drop-down list (at the bottom of the dialog box), choose All Files (*.*). A number of files should now be displayed in the dialog box.
  3. Click once on the hosts file.
  4. Click Save. Notepad informs you that you are about to overwrite an existing file.
  5. Click Yes. Notepad saves the modified hosts file.
  6. Exit Notepad.

Any changes you made to the Hosts file go into effect immediately.

Remember that the primary purpose of the Hosts file is to override what would be found by consulting your regular DNS server. For instance, let's say that you are a Web developer, and your client's current website resolves, through DNS, to an IP address of 222.121.222.122. You are working on a brand-new site for the client, and you have that site set up at a different IP address, such as 222.121.222.201. If you modify your Hosts file to point to the IP address of the new site, then DNS is bypassed and all references on your system to the client's website will resolve to the IP address you entered in the Hosts file.

Another possible use for your Hosts file is to deny access to a particular website. Let's say that your company doesn't allow access to a particular website called ObnoxiousSite.com. You can block access to the website by modifying the Hosts file so that ObnoxiousSite.com is associated with the IP address 127.0.0.1. (As an alternative, you could also use the IP address 0.0.0.0.) Once saved, any references to ObnoxiousSite.com will be ignored on your system.

This brings up a helpful troubleshooting point: Some third-party programs may modify your Hosts file automatically, or your company may create custom Hosts files for systems on your network. If you cannot get to a site you need to get to, you may want to check your Hosts file to see if the site is blocked in the file.

 This tip (12858) applies to Windows 7, 8, and 10.

Author Bio

Barry Dysert

Barry has been a computer professional for over 35 years, working in different positions such as technical team leader, project manager, and software developer. He is currently a software engineer with an emphasis on developing custom applications under Microsoft Windows. When not working with Windows or writing Tips, Barry is an amateur writer. His first non-fiction book is titled "A Chronological Commentary of Revelation." ...

MORE FROM BARRY

Changing a Program's Compatibility Settings

If an older program no longer runs under Windows, you may still be able to get some life out of it by changing its ...

Discover More

Changing How Tasks Appear on the Taskbar

The Windows Taskbar is much more robust than it was in previous versions of the operating system. One of its many ...

Discover More

Defragmenting a Hard Drive

As files are added, removed, and edited on a hard drive, the files and the disk itself become fragmented. This causes ...

Discover More
More WindowsTips

Moving Your Downloads Folder

If you're on the Internet a lot, chances are you do a lot of downloading. By default, your Downloads folder is on your C: ...

Discover More

Using the Hosts File to Block Content

Although there are better methods, you can use the Hosts file to block access to specific websites. This tip tells you how.

Discover More

Creating a Desktop Shortcut for a Favorite Web Page

If you visit a certain Web page frequently, you may wish to create a desktop shortcut to take you there. This tip tells ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 6 + 4?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WindowsTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.