Operating System - Linux
1829115 Members
14184 Online
109986 Solutions
New Discussion

Hosts file Hellllpppppp!!!!!!!

 
SOLVED
Go to solution
manny_9
Frequent Advisor

Hosts file Hellllpppppp!!!!!!!

I am trying to block popup ads. Through my research , I assumed it could be done simply with the hosts file.

Redhat 7.2

xxx.x.xxx.xxx0 someserver.some.net someserver # 0
xxx.x.xxx.xxx0 someserver.some.net someserver # 0
x.x.x.1 someserver.some.net someserver # 0
x.x.x.1 email.some.net email # 0
x.x.x.1 some 0 # 0
x.x.x.1 route.some.org route
xxx.x.xxx.xxx0 mail.some.net 0 # 0
xxx.x.xxx.xxx0 mail.some.net 0 # 0
127.0.0.1 localhost.localdomain localhost # 0
127.0.0.1 www.doubleclick.com


the site can still be accessed. What did i do wrong??!!! what are does 0 # 0 mean

Thanks
9 REPLIES 9
Stuart Browne
Honored Contributor

Re: Hosts file Hellllpppppp!!!!!!!

You want to block a site, use:

127.0.0.1 someserver.some.net

The "# 0" at the end are uselss.

The 'xxx.x.xxx.xxx0' is what's going haywire. the resolver know's it's not an IP so it ignores it.

It's probably better if you're using a cache (squid) to block it in there however.
One long-haired git at your service...
dirk dierickx
Honored Contributor
Solution

Re: Hosts file Hellllpppppp!!!!!!!

it can be done with the host file, in fact there are hostfiles available on the web that have all those "ads" sites listed in one gigantic host file you can just copy to your /etc and off you go.

if you want to do it yourself;
you have to point them to address 127.0.0.1, that is all. the '# 0' has no effect because it is actualy a comment.
Michael Armbrecht
Frequent Advisor

Re: Hosts file Hellllpppppp!!!!!!!

Check your /etc/nsswitch.conf. Make sure that the line starting with the word "hosts" does not list "dns" before "files", because in this case the hosts file is only used when the name resolution via dns fails.
Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.
manny_9
Frequent Advisor

Re: Hosts file Hellllpppppp!!!!!!!

Thanks to everyone!!

I am on my way to work now. Before I go...

Michael,if /etc/nsswitch.conf is using dns. is there still a way to use hosts. or do i have to use iptables. currently i can not make changes (squid). i just need a simple way to block.

Thanks
Michael Armbrecht
Frequent Advisor

Re: Hosts file Hellllpppppp!!!!!!!

Fred,

change the line "hosts" in nsswitch.conf to "files dns". Like this, it first checks /etc/hosts, if it doesn't find the hostname there, it uses dns.
Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.
manny_9
Frequent Advisor

Re: Hosts file Hellllpppppp!!!!!!!

Okay I am slighly confused.
here is the nsswitch conf.

#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
# nisplus or nis+ Use NIS+ (NIS version 3)
# nis or yp Use NIS (NIS version 2), also called YP
# dns Use DNS (Domain Name Service)
# files Use the local files
# db Use the local database (.db) files
# compat Use NIS on compat mode
# hesiod Use Hesiod for user lookups
# [NOTFOUND=return] Stop searching if not found so far
#

# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd: db files nisplus nis
#shadow: db files nisplus nis
#group: db files nisplus nis

passwd: files nisplus
shadow: files nisplus
group: files nisplus

#hosts: db files nisplus nis dns
hosts: files nisplus dns

# Example - obey only what nisplus tells us...
#services: nisplus [NOTFOUND=return] files
#networks: nisplus [NOTFOUND=return] files
#protocols: nisplus [NOTFOUND=return] files
#rpc: nisplus [NOTFOUND=return] files
#ethers: nisplus [NOTFOUND=return] files
#netmasks: nisplus [NOTFOUND=return] files

bootparams: nisplus [NOTFOUND=return] files

ethers: files
netmasks: files
networks: files
protocols: files nisplus
rpc: files
services: files nisplus

netgroup: files nisplus

publickey: nisplus

automount: files nisplus
aliases: files nisplus


Thanks
Alexander Chuzhoy
Honored Contributor

Re: Hosts file Hellllpppppp!!!!!!!

1. see if your web browser is configured with proxy
2. If it is - then set it to bypass the proxy for these "bad" URLs
Nat Guyton
Advisor

Re: Hosts file Hellllpppppp!!!!!!!

Your nsswitch.conf is OK - what matters is that for the hosts line, "files" comes first.

The other thing that might be a problem is multiple line entries for 127.0.0.1. For your example in your original post, consolidate it all on one line, like:

127.0.0.1 localhost.localdomain localhost www.doubleclick.com

Hope this helps!
Never underestimate the bandwidth of a station wagon filled with backup tapes
manny_9
Frequent Advisor

Re: Hosts file Hellllpppppp!!!!!!!

Thanks to everyone for their help!!! I finally have electricity!!!!!!!!!!!!!!!!!!!!!!!!!

127.0.0.1 localhost.localdomain localhost # 0

I can't for the life of me grasp why #0 is being used. Adding the site I wish to block after the #0---- how will it work???

Boy do i feel dumb