LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Blocking websites via /etc/hosts (https://www.linuxquestions.org/questions/linux-networking-3/blocking-websites-via-etc-hosts-774656/)

Deewanagan 12-10-2009 01:04 AM

Blocking websites via /etc/hosts
 
Hi,

so i wanted to block some certain sites from opening on my computer, i googled and found that i can use /etc/hosts file for this purpose. so i added something like this in the file:
Code:

127.0.0.1 www.facebook.com
but it didn't work. any one knows why?
currently i am using iptables for this purpose, but this should also work.

tanx,

catkin 12-10-2009 01:40 AM

Maybe /etc/hosts is not being used. What does resolv.conf look like?

Deewanagan 12-10-2009 03:39 PM

something like this:
Code:

# Generated by NetworkManager
nameserver 10.10.4.1


estabroo 12-10-2009 10:54 PM

I think you might have misread something /etc/hosts is just a ip <-> name resolution file. Maybe you were looking at tcpwrappers and want to do stuff with /etc/hosts.allow and /etc/hosts.deny

catkin 12-11-2009 12:45 AM

Quote:

Originally Posted by Deewanagan (Post 3787035)
something like this:
Code:

# Generated by NetworkManager
nameserver 10.10.4.1


That's /etc/hosts not resolv.conf.

unSpawn 12-11-2009 02:35 AM

...besides, using /etc/hosts to block sites is deprecated (better methods exist), inefficient (management) and incomplete (easy circumvention).

Web31337 12-11-2009 06:19 AM

it is, but it works fine if this computer is a proxy server, the only one plugged into internet and the proxy server doesn't support blocking sites/urls. also by pointing facebook.com to 127.0.0.1 you may create a web server on port 80 and write some message =)

unSpawn 12-11-2009 10:20 AM

Quote:

Originally Posted by Web31337 (Post 3787678)
it is, but

If it really is, then why would you still want to look for counter arguments?..


Quote:

Originally Posted by Web31337 (Post 3787678)
it works fine if this computer is a proxy server, the only one plugged into internet and the proxy server doesn't support blocking sites/urls.

If the proxy software does not fulfill your requirements then why not replace it instead of using a past millennium kludge?

estabroo 12-11-2009 05:34 PM

if you really want to do that make sure in your /etc/nsswitch.conf files is listed before dns in the hosts section

Deewanagan 12-12-2009 09:13 AM

Quote:

Originally Posted by catkin (Post 3787434)
That's /etc/hosts not resolv.conf.

hi,
it is the /ets/resolv.conf file.

Deewanagan 12-12-2009 09:19 AM

Quote:

Originally Posted by estabroo (Post 3788344)
if you really want to do that make sure in your /etc/nsswitch.conf files is listed before dns in the hosts section

i didn't really get what you meant, but the /etc/nsswitch.conf file looks something like this:

Code:

passwd:        compat
group:          compat
shadow:        compat

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
networks:      files

protocols:      db files
services:      db files
ethers:        db files
rpc:            db files

netgroup:      nis


catkin 12-12-2009 09:38 AM

Quote:

Originally Posted by Deewanagan (Post 3788842)
hi,
it is the /ets/resolv.conf file.

My apologies; when I wrote resolv.conf I was thinking of nsswitch.conf :redface:

pluckypigeon 12-13-2009 06:13 AM

So how do we block sites? I can't find anything on this subject except for the BlockSite Firefox Addon that doesn't work anymore.

Dinobot 12-13-2009 06:38 AM

Hi, guys!

I'm still have a trouble with /etc/hosts configuring...

My /etc/hosts/ is:

Quote:

127.0.0.1 localhost
192.168.1.100 vyzhase vyzhase.ru
# End of hosts.
!!!BUT!!!

ping localhost says:

Quote:

ping: unknown host localhost
And the same thing with "vyzhase" and "vyzhase.ru"... What's happens and what's wrong again? =(

unSpawn 12-13-2009 06:50 AM

Quote:

Originally Posted by pluckypigeon (Post 3789585)
So how do we block sites?

Depends. In Opera you would add the site to Preferences > Content > Blocked content, in Firefox you could use an add-on like Adblock and in a system-wide context you'd use a proxy like Privoxy (p.p > current configuration > Edit privoxy/user.action > { +block\n-handle-as-image }\n.site.name\n) or Polipo (echo $site >> polipo/forbidden) or Squid (acl blocked_sites url_regex filename; http_access deny blocked_sites). Using null routes or /etc/hosts is cumbersome, circumventable and incomplete. Who would consider using it when more practical, better performing and complete solutions exist?..


Quote:

Originally Posted by pluckypigeon (Post 3789585)
I can't find anything on this subject except

Depends on what terms you search for. Just being curious what did you use?


All times are GMT -5. The time now is 05:17 AM.