Understanding Your Hosts File

by Barry Dysert
(last updated November 28, 2016)

2

Every single computer accessible through a network (including the network we know as "the Internet") has a unique numeric address known as an IP address. When you are using a browser or other client software, you normally type a URL into the software to specify what you want to see or where you want to take an action. Behind the scenes, this URL is converted into an IP address automatically so that a connection can be made between your client software and the remote server.

This conversion from URL to IP address is typically done using DNS servers. (DNS is an acronym for Domain Naming System.) What most people don't know, however, is that DNS servers are the second place for which IP addresses are checked. The first is a file on your system known as a Hosts file. The Hosts file is a text-based system file that defines the mappings between IP addresses and names. If the host name is located within the Hosts file, then your client software uses the IP address associated with it there rather than querying a DNS server.

The Hosts file lives at "C:\Windows\System32\Drivers\Etc\hosts" (it has no file extension). Since the Hosts file is nothing but a plain text file, you can load it using a text editor such as Notepad. (See Figure 1.)

Figure 1. An example Hosts file.

Notice that most of the lines in the file begin with a hash tag (#, sometimes called a pound sign or a sharp sign). These are comments and are ignored by Windows. Blank lines are also ignored. For lines that aren't ignored, they are formatted simply as the IP address followed by whitespace and the name of the host system (or server) corresponding to that IP address.

If you examine a Hosts file, you may even notice that some lines have a pound sign at a position other than the first character. These are comments, as well, and everything after the pound sign is ignored.

You can easily modify your Hosts file to add as many mappings as you wish. You can even use the Hosts file to prevent access to specified remote systems. Both of these topics are covered under separate tips.

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

Author Bio

Barry Dysert

Barry has been a computer professional for over 30 years, working in different positions such as technical team leader, project manager, and software developer.  He is currently a senior software engineer with an emphasis on developing custom applications under Microsoft Windows. ...

MORE FROM BARRY

Changing Font Size in a Command Prompt Window

If you work at the command level very much, you may want to change the fonts that are used. You can control what typefaces to ...

Discover More

Undoing a System Restore

Having the ability to restore your system back to when it was working properly is great, but what if, for some reason, you ...

Discover More

PowerShell Input and Output

When dealing with a scripting language like PowerShell, one of the first things you need to learn is how to get data into and ...

Discover More
More WindowsTips

Understanding and Controlling Third-Party Cookies

Cookies can be a good thing, but they can also be aggravating. Here's a high-level explanation about a specific type of ...

Discover More

Setting the Default Browser

Some people are passionate about the browser they use to access the Web. If you have a favorite browser that you want to set ...

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
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. 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 seven more than 5?

2016-11-28 10:43:09

allen@sharonparq.com

Ned, see here:

http://windows.tips.net/C0257

Look for any tip on that page that references "hosts".

-Allen


2016-11-28 10:39:28

Ned

Where are the tips that cover how to modify and/or prevent access to specified remote systems in the Hosts file?

Nadim


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.