6 Surprising Uses For The Windows Hosts File

windows hosts fileThe Windows Hosts file allows you to define which domain names (websites) are linked to which IP addresses. It takes precedence over your DNS servers, so your DNS servers may say facebook.com is linked to a specific IP address, but you can have facebook.com go anywhere you want. The Windows Hosts file can be used to block websites, redirect them, create shortcuts to websites, create your own local domains, and more.

We’ve previously covered using the Windows Hosts file to block websites without installing any other software on your computer – it’s often used for quick website blocking by geeks in the know.

Editing The Windows Hosts File

To edit your Hosts file, you’ll need to open Notepad (or any other text editor you like, such as Notepad++) as Administrator. To do so, click Start, type Notepad into the Start menu, right-click the Notepad shortcut and select Run as Administrator.

After you have, click File and Open in the Notepad window, then browse to the C:\Windows\System32\drivers\etc folder. Click the Text Files box at the bottom right corner of the window, select All Files, and double-click the hosts file.

windows hosts file

Changes you make to the hosts file will take effect immediately after you save the file – you don’t have to reboot. If you’re adding multiple entries to your hosts file, ensure each is on its own line.

Block a Website

To block a website, add a line like the following one to the bottom of the hosts file:

127.0.0.1 example.com

windows hosts

What this does is simple – 127.0.0.1 is the IP address’ of your local computer. When you navigate to example.com, your computer will try to connect to itself (127.0.0.1). Your computer probably won’t find a web server running on itself, so the connection will fail immediately, effectively blocking the website from loading.

windows hosts

Redirect a Website

You can also use this trick to redirect a website to another website. For example, let’s say we want to redirect facebook.com to twitter.com – so when we type facebook.com into our address bars, we’ll end up at Twitter.

First, we’ll need Twitter’s IP address. To find it, we can use the ping command in a Command Prompt window (click Start, type Command Prompt, and press Enter to open one). Type ping twitter.com into the command prompt window and you’ll see Twitter’s numerical IP address.

windows hosts

Now we can add the following line to our hosts file:

199.59.150.39 facebook.com

This line tells our computer to connect facebook.com to Twitter’s IP address. Type facebook.com and you’ll end up at Twitter!

Create Website Shortcuts

You can also use this trick to create “shortcuts” that quickly access websites from any program on your computer. For example, if you’re a Twitter addict, you can associate “t” with Twitter – type t in any web browser’s address bar and you’ll instantly end up at Twitter. You can also create shortcuts with multiple letters, such as twit. You don’t need a .com, .net, .org, or any other type of extension. However, you can’t use spaces.

To do this, just add the following line to the hosts file and save it:

199.59.150.39 t

You can get the exact IP address you’ll need by using the ping command mentioned above.

Now you can type t into any program’s address bar and you’ll end up at twitter.com.

windows hosts file use

Assign Local Domain Names

You can also create local domain names for your computers. For example, if you have a local server that you use, you can name it server and quickly access it by typing server as the URL into any program. If you frequently access your router’s configuration page, you can associate the word router with your router’s IP address and type router into your web browser’s address bar to access your router.

Note that you’ll need the computer or router’s IP address before doing this. After you have it, enter a line like the following – the following line associates 192.168.0.1, an IP address commonly used by routers, with the domain name router:

192.168.0.1 router

You can replace the IP address and domain name here with anything you like.

Test A Web Server That Uses Host Headers

If you’re running a web server on your local network, you may want to make sure it’s working properly before exposing it live on the Internet. Some web servers run multiple websites at the same IP address – the website you get depends on the host name you’re accessing. In cases like this, it’s not helpful to simply access the web server at its local IP address – you need to access it at its website addresses.

For example, if you have a web server with the local IP address 192.168.0.5 that hosts websites for company.com and organization.org, you can add the following lines to your local computer’s hosts file:

192.168.0.5 company.com

192.168.0.5 organization.org

After saving the file, try to access both company.com and organization.org in your web browser – if everything is working properly, you should see the different websites. The server notices your headers specify company.com or organization.org and serves the correct website. If this doesn’t work, you have some troubleshooting to do before deploying the server on the Internet!

windows hosts file use

Block Lists of Websites

Some people create their own lists of websites they want to block and publish them online. You can block these lists of websites by copying one of these lists into your hosts file.

Check out the following article for some recommended lists you can use, along with a graphical tool that makes downloading these hosts files to your computer and using them easy:

windows hosts file

If you want to revert any changes you’ve made, simply delete the lines you added to the bottom of the file, then save the file.

What do you use your Windows hosts file for? Leave a comment and share any tricks you have!

Image Credit: Network Cables via Shutterstock


MakeUseOf Recommends

More articles about:

21 Comments

Chris Hoffman

Chris Hoffman is a tech blogger and all-around technology addict living in Vancouver, BC. Connect with him on Google+ or Twitter.

The comments were closed because the article is more than 180 days old.

If you have any questions related to stuff mentioned in the article or need help with any computer issue, just ask it on MakeUseOf Answers.

Hide 21 Comments

  • Sebastian Hadinata September 22, 2012
    0 likes

    Great Article, nice tips on using host file as Website Shortcuts.

    | Like
  • Vijaynand Mishra September 22, 2012
    0 likes

    wow

    | Like
  • Marko Resnik September 23, 2012
    0 likes

    Cool. Now I can un-block any website that is unavailable in my region. Thank you, Chris Hoffman!

    | Like
    • Hamada September 23, 2012
      0 likes

      Marko, i think you didn’t get it. This is not to un-block site that is unavailable in your region, it will not even help ((.
      Read the article again carefully and you will understand.

      | Like
    • Hamada September 23, 2012
      0 likes

      Marko, i think you didn’t get it. This is not to un-block site that is unavailable in your region, it will not even help ((.
      Read the article again carefully and you will understand.

      | Like
      • Chris Hoffman September 29, 2012
        0 likes

        Correct, unfortunately this won’t unblock sites — it will block them though.

        | Like
    • CO December 15, 2012
      0 likes

      Hi Marko,

      You can work around blocked websites by using a proxy site that is not
      on the blocked list.

      Once you can access a proxy website through which you can access the blocked site, then you will be able to access those blocked site but only through the proxy. The proxy could be in the form of a proxy website or a remote machine that you have access to.

      | Like
  • GrrGrrr September 23, 2012
    0 likes

    I liked the idea of using shortcuts. it will save a lot of keystrokes

    | Like
    • HLJonnalagadda September 25, 2012
      0 likes

      Yeah very useful!

      | Like
  • nk September 24, 2012
    0 likes

    can you tell me how to unblock blocked sites

    | Like
    • CO December 15, 2012
      0 likes

      Hi nk,

      You can work around blocked websites by using a proxy site that is not
      on the blocked list.

      Once you can access a proxy website through which you can access the blocked site, then you will be able to access those blocked site but only through the proxy. The proxy could be in the form of a proxy website or a remote machine that you have access to.

      | Like
  • HLJonnalagadda September 25, 2012
    0 likes

    Awesome. I didnt know the hosts file had such utility.

    | Like
  • Pawan Kj September 26, 2012
    0 likes

    Thank you! this one is useful. Feature to explore without having a software to be installed :)

    | Like
  • venkatachalam ravindran September 28, 2012
    0 likes

    Thanks for the article. Blocking websites, using shortcuts like ‘router’ are very useful. Somehow the local hosts file seems to have been ignored…

    | Like
  • Paveliuc Bogdan October 6, 2012
    0 likes

    I always forget my router IP. thanks!

    | Like
  • jafar November 6, 2012
    0 likes

    It has been done on my computer thanks . But how can i put the comments on blocked site’s Ex : this site blocked by HR Admin like this . if you don’t mind please explain to me

    | Like
    • Chris Hoffman November 7, 2012
      0 likes

      Just include a line with a # symbol in front of it. Any line with # in front of it is ignored.

      In other words, do something like this:

      #This site was blocked by HR
      127.0.0.1 example.com

      | Like
  • Andile November 8, 2012
    0 likes

    You are a life saver bra. Thanx alot

    | Like
  • James February 22, 2013
    0 likes

    I noticed that even when a website is blocked using the hosts file it is still possible to ping the site. Is there a technique to block even the ping?

    | Like
    • Tina Sieber March 1, 2013
      0 likes

      James,

      I’m afraid I don’t know of a solution, but you could try to ask a question at MakeUseOf Answers and see what folks over there come up with. Good luck!

      | Like
    • wschloss March 16, 2013
      0 likes

      My browsers (3) don’t seem to be respecting my hosts file changes. I’m pretty sure I modified it correctly. Does a service need to be enabled or some such? Thanks.

      | Like