Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Hosts File : Use in Windows 7 / Vista

Hosts File : Use in Windows 7 / Vista

How to Access and Use the Hosts File in Vista, Windows 7, and Windows 8
Published by Bare Foot Kid
14 Apr 2010
Published by

How to Access and Use the Hosts File in Vista, Windows 7, and Windows 8
This will give you the basics on how to use the Windows Hosts File, it's not very complicated but it's up to each individual to find additional information and put it to good use to suite your needs.

Note   Note
To block a site this " localhost" (without the quotes) must be the first entry in the Hosts File, you can add any comments to the file using this ( # ) symbol at the front of the comment; each entry needs its own line and there must be at least 1 space between the IP address and the host name; this info can be viewed in the #1 snip below of the default Windows 7 Hosts File.
Some sites have more than one IP address so to completely block a specific site you may need to add more than one entry to completely block such sites.
Tip   Tip
As any additions / changes to the Hosts File can / will be removed using a System Restore point dated before the work was done with the file, it may be a good idea to create Restore Points before and after any changes are made to the Hosts File, see the tutorial at the link below.

System Restore Point - Create

It would also be advisable to clear the DNS Resolver Cache whenever you finish working with the Hosts File, open an elevated command window and type "ipconfig /flushdns" (without the quotes) and hit enter.
Let's get started!

Option One
Block a Site

1) In the Windows start menu search box type "notepad" (without the quotes) right click the entry and select "Run as Administrator" then enter your user credentials for the UAC prompt and click yes to open notepad. In notepad at "File" select "Open" then browse to C:\Windows\System32\drivers\etc in the window that opens select "All Files" then "hosts" then click "Open" to open the default Windows Hosts File location.
Name:  Notepad Runas.jpg
Views: 26540
Size:  62.5 KB
Name:  UAC_Notepad.jpg
Views: 26173
Size:  80.9 KB
2) The #1 snip below is the default Windows 7 Hosts File that opens, as you can see with the use of this ( # ) symbol, Windows does not "read" any of the default information in the file, so it's up to you whether to delete it all or not but it may be useful to leave it there for future reference.
3) If I wanted to block access to, the first entry in the file would need to be localhost on its own line, on the next line I would add with at least 1 space between the IP address and the host name; then back at "File" select "Save" then "Exit" to close notepad.

Option Two
Re-direct a Site

If I wanted to re-direct to I would add the IP address for on its own line seperated by at least 1 space then, and if I wanted to add comments I would put them after the # symbol; then at "File" select "Save" then "Exit" to close notepad.

Option Three
Ping a Site

To ping a site to get the IP address, open a command window (it doesn't have to be elevated) type "ping" then hit enter, as you can see in the snip there's one of the IP addresses for; those are common ping commands in the "Code" box below.
Name:  Ping_ebay.jpg
Views: 26535
Size:  75.3 KB
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\Bare Foot Kid>ping /?
Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name
    -t             Ping the specified host until stopped.
                   To see statistics and continue - type Control-Break;
                   To stop - type Control-C.
    -a             Resolve addresses to hostnames.
    -n count       Number of echo requests to send.
    -l size        Send buffer size.
    -f             Set Don't Fragment flag in packet (IPv4-only).
    -i TTL         Time To Live.
    -v TOS         Type Of Service (IPv4-only. This setting has been deprecated
                   and has no effect on the type of service field in the IP Head
    -r count       Record route for count hops (IPv4-only).
    -s count       Timestamp for count hops (IPv4-only).
    -j host-list   Loose source route along host-list (IPv4-only).
    -k host-list   Strict source route along host-list (IPv4-only).
    -w timeout     Timeout in milliseconds to wait for each reply.
    -R             Use routing header to test reverse route also (IPv6-only).
    -S srcaddr     Source address to use.
    -4             Force using IPv4.
    -6             Force using IPv6.
14 Apr 2010   #1
Capt.Jack Sparrow

Windows 7 Ultimate - 64-bit | Windows 8 Pro - 64-bit

Great Work Jr. Brink

My System SpecsSystem Spec
14 Apr 2010   #2

Vista Ult 64 bit Seven Ult RTM x64

Good info Ted. Thanks.
My System SpecsSystem Spec
14 Apr 2010   #3
Bare Foot Kid
Microsoft MVP

W 7 64-bit Ultimate

Quote   Quote: Originally Posted by Capt.Jack Sparrow View Post
Great Work Jr. Brink
Quote   Quote: Originally Posted by garysgold View Post
Good info Ted. Thanks.

Hello Cap'n and Gary, thanks!
My System SpecsSystem Spec

14 Apr 2010   #4

Windows 7 Ultimate 32 bit

Very good instructions, Ted. Great job.
My System SpecsSystem Spec
14 Apr 2010   #5
Bare Foot Kid
Microsoft MVP

W 7 64-bit Ultimate

Thanks Carl!
My System SpecsSystem Spec
14 Apr 2010   #6
Microsoft MVP

Vista, Windows7, Mint Mate, Zorin, Windows 8

Very nice, thank you. That merits some reps.
My System SpecsSystem Spec
14 Apr 2010   #7
Bare Foot Kid
Microsoft MVP

W 7 64-bit Ultimate

Thank you very much!
My System SpecsSystem Spec
14 Apr 2010   #8

Windows 7 Professional

Thanks for doing this. You may want to add that you can also 'tab' the IP/Hostname entries to make neat looking columns.
My System SpecsSystem Spec
14 Apr 2010   #9
Bare Foot Kid
Microsoft MVP

W 7 64-bit Ultimate

Hello Jeff, you're welcome.
My System SpecsSystem Spec

 Hosts File : Use in Windows 7 / Vista

Tutorial Tools

Similar help and support threads
Windows 7 Tutorial Category
error messages with windows defender, hosts file & microsoft essential
Hi, I can't open my hosts file. i want to block websites. when i right click on the hosts file to run as administrator i get . I cant open windows defender. When i click on it i get error message i can't install microsoft essentials. this just happened recently when i had a virus or malware...
System Security
Hosts file ignored and replaced with hosts.original
Hello. I am trying to use the hosts file. However both pings and web addresses still bypass the hosts file. I noticed that there is another file in the C:\Windows\System32\drivers\etc directory called 'hosts.original'. When ever I delete this file, it reappears seconds later. I have made sure that...
General Discussion
Hosts File
Hey, I was wondering, is there any internet performance gain if you put a commonly used website's IP (like Google) in your Hosts file, so it doesn't need to ask a DNS server? I mean, because I have 30 websites I go on at least 10 times each day, and it lags when I open all of them :D Thanks!
General Discussion
Hosts file-S??
can the hosts file be changed to, or amended by, another file? IOW can there be a file named xyz that essentially replaces the hosts file, or adds entries to it? Possibly by a registry key or configuration setting? Of course it could by altering library fxns, but by other "simpler" means? ...
System Security
HOSTS File - Create a "Edit HOSTS file" Shortcut
How to Create a "Edit HOSTS file" Shortcut in Windows 7 and Vista The HOSTS file is a .txt file used in Vista and Windows 7 to map hostnames to IP addresses. Your computer checks this file first to resolve any network names to its corresponding IP address before it tries to check the Internet....
how to set etc/hosts file in windows 7
I updated the Windows\System32\drivers\etc\hosts file to include static ip addresses of computers on my local network; just like I do it in Vista and XP. But now I tried to access the computers by name, it complains that host 'xyz' cannot be resolved. Why? Simon
Network & Sharing

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 16:24.

Twitter Facebook Google+

Windows 7 Forums

Seven Forums Android App Seven Forums IOS App