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 and lmhosts

19 Apr 2011   #11
colinearpsycho

7 home premium 64-bit
 
 

before you said that if i had an entry in the hosts file it wouldn't prevent traffic to that website, if i entered it in internet explorer. either that, or are you saying the fact that it doesn't SOUNDS like i have a virus that is redirecting traffic locally? however you answer those inquiries, how can i make sure that IE uses the local hosts file to some degree...then again, if i have a hosts file, what is the point of the dns service in administrative tools/services? i've read that having a very long hosts file, will see better use and performance if that service is turned off. so it shouldn't be difficult to see from this botched up mess how confusing this becomes.

Quote:
OR if you find that for some reason your DNS server is returning bad addresses for say Google you can put in something like

www.google.com 74.125.224.171

And instead of using DNS it will use that known good address for google.
in that quote you're talking about lmhosts file right? because if you're still talking about the aforementioned hosts file, then it's just all the more confusing and the trouble is, it's the same pathetic answer from the entire internet (and i don't mean to sound a prick, but you google it and see what you can come up with, it's taxing). also whether you're talking about hosts or lmhosts you have the syntax backwards, it's loopback domain name ip for hosts and ip domain # for lmhosts.


My System SpecsSystem Spec
.
19 Apr 2011   #12
pparks1

Windows 7 Ultimate x64
 
 

LMHosts file is for handling windows workgroup and domain nanming when methods such as WINS fails. This is not for resolving names of websites and such on the Internet. It's for the local network. LM stands for LAN Manager. So, LMHOSTS is a LAN MANAGER hosts file. This is for resolving things like the NETBIOS name of the machine.
LMHOSTS - Wikipedia, the free encyclopedia.

Now, some people don't care whatsoever about a netbios name of their computer. For example, Linux boxes aren't configured with that at all. They just have a local hostname on the box....and all name resolution is strictly done with DNS or a hosts file. So, it's not absolutely required that you have both configured.

If you have a hosts file on your computer (C:\Windows\system32\drivers\etc\hosts), then Windows will use this file without question to resolve the IP address for the website you are attempting to find. Same thing happens in linux, but here the file is /etc/resolv.conf. If you want to test that it's working, put in 10.10.10.1 for www.google.com...then try to hit Google in your IE web browser. If you do NOT get the Google web page, you know that your machine is indeed using HOSTS and not DNS to resolve that name.

The DNS client service allows your computer to use DNS to look things up on the Internet. While you can shut this off, it would break pretty much everything on the Internet that you didn't manually specify in your hosts file. While a hosts file can improve performance (as it doesn't need to look up the address in DNS on the Internet), these lookups are nearly instantaneous. Plus, if you hard code a web page into a HOSTS file and the person running the website decides to move it to another IP address...your access will break until you figure out what the new IP address is and then adjust your hosts file accordingly. Seriously, I wouldn't even consider shutting off DNS in favor of HOSTS for any type of performance reason. You will spend far more time troubleshooting why nothing works properly on your machine which will far outweight any times savings in DNS lookups.

the syntax for HOSTS, is
x.x.x.x www.domainname.com

If there is any confusion, look at the same lines MS provides in their file. And the # means the line is commented out...thus won't work.
Code:
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
My System SpecsSystem Spec
19 Apr 2011   #13
fseal

Windows 7 x64 Ultimate
 
 

Oops yeah I used the OPs example and got the entries reversed for the hosts file sorry
My System SpecsSystem Spec
.

19 Apr 2011   #14
danforward

Windows 7 Ultimate N
 
 

Forget about lmhosts.sam. It is a SAMPLE file and does nothing. It shows examples of what can be done in the lmhosts file, which is not what you want either.

When your computer tries to resolve the IP address for a website, it first looks in your C:\Windows\System32\drivers\etc\hosts file. If it is not found in there, it checks your DNS cache. If not in there, it will contact your DNS server. That is what makes your hosts file such a great place to block unwanted web sites. It always gets checked first.

It does not really matter what IP address you assign to web sites you want to block. 127.0.0.1 is usually a good choice, unless you run a web server on your machine. It just tells your computer to go to your machine rather than theirs, which of course fails. I prefer to use 0.0.0.0 because it is never a valid machine.

So, to achieve the effect you want, append the entries to your hosts files like this:

0.0.0.0 doubleclick.net www.doubleclick.net
0.0.0.0 badsite.com www.badsite.com ads.badsite.com

The format is an IP address followed by spaces or tabs, followed by one or more domain names separated by spaces or tabs. In theory you could put all sites you want to block on one line. In practice, it is easier to manage by placing one domain on each line or related domains on each line as I have done above. I could have just as easily done this:


0.0.0.0 doubleclick.net
0.0.0.0 www.doubleclick.net
0.0.0.0 badsite.com
0.0.0.0 www.badsite.com
0.0.0.0 ads.badsite.com

or this:


0.0.0.0 doubleclick.net www.doubleclick.net badsite.com www.badsite.com ads.badsite.com
My System SpecsSystem Spec
19 Apr 2011   #15
WebMattR

W7 Professional x64
 
 

Quote   Quote: Originally Posted by danforward View Post
It does not really matter what IP address you assign to web sites you want to block. 127.0.0.1 is usually a good choice, unless you run a web server on your machine. It just tells your computer to go to your machine rather than theirs, which of course fails. I prefer to use 0.0.0.0 because it is never a valid machine.
The problem with this usage of the host files is that it will slow down every query your machine makes, because it has to compare that to each individual entry in the hosts file. I seriously suggest you simply install antivirus, run a firewall, and forget this entire idea. it's just going to kludge things up for you. You can't add sites fast enough for it to ever be relevant, and every entry slows your ability to use the internet down a little, since it has to be scanned for every query that goes out.
My System SpecsSystem Spec
19 Apr 2011   #16
SledgeDG

Windows 7 Ultimate x86
 
 

You're not serious, are you?
Unless you cramp your hosts with literally thousands of lines, in the time your computer does 1 DNS query it could probably do some 500 queries of the local hosts file .
I don't think that one shouldn't worry about any speed concerns in this context

-DG
My System SpecsSystem Spec
19 Apr 2011   #17
fseal

Windows 7 x64 Ultimate
 
 

Yeah, the hosts file can be actually be used to speed up your internet surfing by hard coding local lookups for sites you visit often (Though you may have to keep them up to date now and then). DNS queries are one of the major slowdowns of web surfing... (That and the BW to DL all the images and ad spam, which is why all these browser speed tests are really amusingly misplaced in 99% of all cases)
My System SpecsSystem Spec
19 Apr 2011   #18
WebMattR

W7 Professional x64
 
 

Quote   Quote: Originally Posted by SledgeDG View Post
You're not serious, are you?
Unless you cramp your hosts with literally thousands of lines, in the time your computer does 1 DNS query it could probably do some 500 queries of the local hosts file .
I don't think that one shouldn't worry about any speed concerns in this context

-DG
I was/am serious. I was told that by the guy who taught my CCNA course.
My System SpecsSystem Spec
19 Apr 2011   #19
SledgeDG

Windows 7 Ultimate x86
 
 

Just think about it for a sec (hard drive access time/RAM access times once it's cached compared to the time a query to your DNS takes with all your average net latency and stuff.
Still we're haggling about milliseconds here. that's why I said that this is nothing to be worried about.
I'm not question the qualification of your teacher. Maybe said guy had a bad day or the whole story had a different context who knows... but I have bee told BS before even from guys who should know better

Anyways..I leave it at that I wasn't trying to convince anyone

-DG
My System SpecsSystem Spec
19 Apr 2011   #20
colinearpsycho

7 home premium 64-bit
 
 

well that clears up the issues about hosts. i have to admit though i'm still a little fuzzy when some of you are referring to hosts or lmhosts. when i read the descriptions provided by ms, they are distinctly different pages, so presuming one is useless to the other is apparently only a matter obstascles in resolution.

lmhosts for use with netbios is a register then

&

hosts is a file which redirects traffic

in conversation, hosts doesn't sound unlike http redirection and lmhosts doesn't sound to far unlike default document, except that it is a name resolution for a (hopefully) overseen page on the network or webpage.

insofar as the example of inputting 10.10.10.1 and google, you mean to place that in lmhosts if i'm correct? i attempted to look up 10.0.0.1 simply by typing it into IE (which it's settings don 't permit the submission of unknown addresses), and it popped up a very broad search result for a number of webpages, and I did not see google listed therein. google pings are also not coming back from 10.10.10.1.

and I should add that having input entries into hosts in the required syntax, and still being able to reach a webpage is disconcerting, i should think i would be getting an error, or loading hang. so hosts also doesn't seem far from default document in addition to http redirection. which i've noticed, because if i input an unavailable domain, the web server returns with very similarly comprised css pages advertising domain sales.
My System SpecsSystem Spec
Reply

 hosts and lmhosts




Thread Tools




Similar help and support threads
Thread Forum
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.txt or hosts.sys
in the drivers/etc folder is: hosts.txt and hosts.sys. I want to edit the hosts file but i dont know is it hosts.txt Or hosts.sys. Oh, theres a file called Hosts without extension on my diffrent pc too. Can you tell me is it safe to edit hosts file as well? The hosts file witout extension...
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...again...but differed
i put some of the network computers on my hosts list, to try and circumvent some issues and lost internet connectivity. none of the ip addresses are listed as the subnet, default gateway; etc. they were just ip's of other computers that connect to this network at times. why did that happen? is it...
Network & Sharing
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....
Tutorials
HOSTS file
I setup a hosts file in windows xp in order to use my website locally using the exact domain name by editing the hosts file by adding the line: 127.0.0.1 www.test.com This should resolve my local ip address for the test.com site and if apache is running, then it should load the website...
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 07:32.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App