Go Back  FlyerTalk Forums > Travel&Dining > Travel Technology
Reload this Page >

Question on using the hosts file

Question on using the hosts file

Old Feb 27, 2015, 10:32 am
  #1  
FlyerTalk Evangelist
Original Poster
 
Join Date: Nov 2002
Location: Freeload Univ. Where are you sitting?
Posts: 14,818
Question on using the hosts file

Just resurrected an older laptop and testing it out. I noticed that one particular site was downloading a bunch of ad-related stuff, and I thought, "Of course! I never put in the hosts file."

I couldn't find the one I had been using (~650K) so I googled around and found one from Malwarebytes. I figured these guys ought to know what they're doing, so I downloaded it and installed it. 30 megs. Are you kidding?

Anyhow, I picked an entry at random (let's call it www.dumbsite.com) and put that address in the browser. What I expected to happen was nothing - it would find the entry in the hosts file, try to connect to myself (127.0.0.1) and that would be it. Instead, it went to the site.

So ... I'm probably misunderstanding how this stuff works (nothing new here, folks).

1. Does it matter which browser I use (IE, Chrome, Opera)?

2. Is that how it really works? It first checks the hosts file, then the internal dns cache and then sends out to the ISP's DNS server. If not, what's going on here?
BigLar is offline  
Old Feb 27, 2015, 12:12 pm
  #2  
 
Join Date: May 2004
Location: Exclusively OMNI/PR, for Reasons
Posts: 4,188
Originally Posted by BigLar
Just resurrected an older laptop and testing it out. I noticed that one particular site was downloading a bunch of ad-related stuff, and I thought, "Of course! I never put in the hosts file."

I couldn't find the one I had been using (~650K) so I googled around and found one from Malwarebytes. I figured these guys ought to know what they're doing, so I downloaded it and installed it. 30 megs. Are you kidding?

Anyhow, I picked an entry at random (let's call it www.dumbsite.com) and put that address in the browser. What I expected to happen was nothing - it would find the entry in the hosts file, try to connect to myself (127.0.0.1) and that would be it. Instead, it went to the site.

So ... I'm probably misunderstanding how this stuff works (nothing new here, folks).

1. Does it matter which browser I use (IE, Chrome, Opera)?

2. Is that how it really works? It first checks the hosts file, then the internal dns cache and then sends out to the ISP's DNS server. If not, what's going on here?
Is the entry in the hosts file to dumbsite.com or www.dumbsite.com? For the type of test you're doing (i.e. via web browser) it's important that you specify the name exactly as it appears in the hosts file. And some browsers will try to "do the right thing" and prepend a www to the name.

Also, if your browser is configured to use a proxy, the hosts file will essentially be ignored.
Dodge DeBoulet is offline  
Old Feb 27, 2015, 1:28 pm
  #3  
FlyerTalk Evangelist
 
Join Date: Nov 2002
Location: ORD
Posts: 14,197
Using the hosts file for ad blocking has always seemed silly to me. It's really not designed for this. How about just using ....... Plus or a similar plugin? Also, OpenDNS will automatically filter out known malware domains. The best part about both is that you don't have to update their lists, like you would with a hosts file.
gfunkdave is offline  
Old Feb 27, 2015, 2:52 pm
  #4  
 
Join Date: Jul 2014
Location: North Sentinel Island
Programs: UA Gold, BONVOY TIT
Posts: 777
I've only used the hosts file for pranks. #2 in your post is pretty much correct as to how it works.
rdurlabhji is offline  
Old Feb 27, 2015, 3:20 pm
  #5  
 
Join Date: Dec 2009
Location: RDU
Programs: DL DM+(segs)/MM, UA Ag, Hilton DM, Marriott Ti (life Pt), TSA Opt-out Platinum
Posts: 3,218
What OS? To make sure you have the right path to file...

In most OSes, the format is:

127.0.0.1 dumbsite.com
127.0.0.1 anotherdumbsite.com

You should be able to use ping or nslookup to verify that it works. In Windows and most *nix systems and on OS X it's effective as soon as you save the file.

Browser doesn't matter.
HDQDD is offline  
Old Feb 27, 2015, 3:54 pm
  #6  
FlyerTalk Evangelist
Original Poster
 
Join Date: Nov 2002
Location: Freeload Univ. Where are you sitting?
Posts: 14,818
Originally Posted by HDQDD
What OS?
Windows 7 and XP.
Originally Posted by HDQDD
In most OSes, the format is:

127.0.0.1 dumbsite.com
127.0.0.1 anotherdumbsite.com
The format is correct.
Originally Posted by HDQDD
You should be able to use ping or nslookup to verify that it works.
I tried pinging (command prompt) using the exact spelling as in the file and it substitutes the appropriate alias (if necessary), fills in the proper IP address, and proceeds to ping the right guy and get a response. Nslookup finds the right guy, too. Clearly it seems to be ignoring the file or I'm misusing it.
BigLar is offline  
Old Feb 27, 2015, 5:30 pm
  #7  
 
Join Date: May 2009
Location: SEA
Programs: AA EXP (2.5MM), Hilton Gold, Marriott Titanium
Posts: 4,859
Originally Posted by BigLar
Windows 7 and XP.
The format is correct.
I tried pinging (command prompt) using the exact spelling as in the file and it substitutes the appropriate alias (if necessary), fills in the proper IP address, and proceeds to ping the right guy and get a response. Nslookup finds the right guy, too. Clearly it seems to be ignoring the file or I'm misusing it.
What is the full path to the file your hosts file? Did you accidentally save it as .txt or something?
mikelat is offline  
Old Feb 27, 2015, 6:27 pm
  #8  
FlyerTalk Evangelist
Original Poster
 
Join Date: Nov 2002
Location: Freeload Univ. Where are you sitting?
Posts: 14,818
Contrary to what I've been told, I did a reboot - at that time, the hosts file was read in, and now everything on the list winds up being unreachable (according to ping).

Which is what I wanted.

I generally put my computers to sleep rather than shut down, so I got out of the habit of rebooting.
BigLar is offline  
Old Feb 28, 2015, 6:27 am
  #9  
 
 
Join Date: Nov 2000
Location: Upcountry Maui, HI
Posts: 13,299
Originally Posted by BigLar
Contrary to what I've been told, I did a reboot - at that time, the hosts file was read in, and now everything on the list winds up being unreachable (according to ping).

Which is what I wanted.

I generally put my computers to sleep rather than shut down, so I got out of the habit of rebooting.
that's weird, I don't have to reboot with win7. Changes to the hosts file are applied immediately. I just tested it with yahoo.com, entry in the file, ping used that, entry not in the file, ping used dns. No reboot, just edit the file.

I wonder if there's a policy for it somewhere, similar to nsswitch.conf?

Yeah, there is, post #2 in this thread:

http://h30499.www3.hp.com/t5/Systems...8#.VPHCl1PF-Qw

My values were the same as what he reported. Are yours different?

-David

Last edited by LIH Prem; Feb 28, 2015 at 6:40 am
LIH Prem is offline  
Old Feb 28, 2015, 10:42 am
  #10  
FlyerTalk Evangelist
 
Join Date: Jun 2005
Posts: 38,320
Originally Posted by gfunkdave
Using the hosts file for ad blocking has always seemed silly to me. It's really not designed for this. How about just using ....... Plus or a similar plugin? Also, OpenDNS will automatically filter out known malware domains. The best part about both is that you don't have to update their lists, like you would with a hosts file.
Yeah, ....... updates automatically. Using the hosts file is something you have to update manually.
Loren Pechtel is offline  
Old Feb 28, 2015, 11:48 am
  #11  
 
Join Date: Dec 2009
Location: RDU
Programs: DL DM+(segs)/MM, UA Ag, Hilton DM, Marriott Ti (life Pt), TSA Opt-out Platinum
Posts: 3,218
Originally Posted by BigLar
Contrary to what I've been told, I did a reboot - at that time, the hosts file was read in, and now everything on the list winds up being unreachable (according to ping).
Yeah, that's because you're still running XP. Maybe if you submit a help ticket with MS, they'll fix it.

Alternatively, you could use: ipconfig /flushdns to flush the dns resolver cache.
HDQDD is offline  

Thread Tools
Search this Thread

Contact Us - Manage Preferences - Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service -

This site is owned, operated, and maintained by MH Sub I, LLC dba Internet Brands. Copyright © 2024 MH Sub I, LLC dba Internet Brands. All rights reserved. Designated trademarks are the property of their respective owners.