LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 12-10-2009, 01:04 AM   #1
Deewanagan
Member
 
Registered: Sep 2008
Posts: 54

Rep: Reputation: 15
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,
 
Old 12-10-2009, 01:40 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,512
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
Maybe /etc/hosts is not being used. What does resolv.conf look like?
 
Old 12-10-2009, 03:39 PM   #3
Deewanagan
Member
 
Registered: Sep 2008
Posts: 54

Original Poster
Rep: Reputation: 15
something like this:
Code:
# Generated by NetworkManager
nameserver 10.10.4.1
 
Old 12-10-2009, 10:54 PM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,092
Blog Entries: 2

Rep: Reputation: 109Reputation: 109
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
 
Old 12-11-2009, 12:45 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,512
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
Quote:
Originally Posted by Deewanagan View Post
something like this:
Code:
# Generated by NetworkManager
nameserver 10.10.4.1
That's /etc/hosts not resolv.conf.
 
Old 12-11-2009, 02:35 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,524
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
...besides, using /etc/hosts to block sites is deprecated (better methods exist), inefficient (management) and incomplete (easy circumvention).
 
Old 12-11-2009, 06:19 AM   #7
Web31337
Member
 
Registered: Sep 2009
Location: Russia
Distribution: Gentoo, LFS
Posts: 399
Blog Entries: 71

Rep: Reputation: 65
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 =)
 
Old 12-11-2009, 10:20 AM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,524
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
Quote:
Originally Posted by Web31337 View Post
it is, but
If it really is, then why would you still want to look for counter arguments?..


Quote:
Originally Posted by Web31337 View Post
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?
 
Old 12-11-2009, 05:34 PM   #9
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,092
Blog Entries: 2

Rep: Reputation: 109Reputation: 109
if you really want to do that make sure in your /etc/nsswitch.conf files is listed before dns in the hosts section
 
Old 12-12-2009, 09:13 AM   #10
Deewanagan
Member
 
Registered: Sep 2008
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by catkin View Post
That's /etc/hosts not resolv.conf.
hi,
it is the /ets/resolv.conf file.
 
Old 12-12-2009, 09:19 AM   #11
Deewanagan
Member
 
Registered: Sep 2008
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by estabroo View Post
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
 
Old 12-12-2009, 09:38 AM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,512
Blog Entries: 27

Rep: Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174Reputation: 1174
Quote:
Originally Posted by Deewanagan View Post
hi,
it is the /ets/resolv.conf file.
My apologies; when I wrote resolv.conf I was thinking of nsswitch.conf
 
Old 12-13-2009, 06:13 AM   #13
pluckypigeon
LQ Newbie
 
Registered: Jan 2009
Distribution: Arch
Posts: 7

Rep: Reputation: 0
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.
 
Old 12-13-2009, 06:38 AM   #14
Dinobot
Member
 
Registered: Nov 2009
Location: Not far from Moscow, Russia
Distribution: Slackware (forever!)
Posts: 46

Rep: Reputation: 15
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? =(
 
Old 12-13-2009, 06:50 AM   #15
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,524
Blog Entries: 51

Rep: Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601Reputation: 2601
Quote:
Originally Posted by pluckypigeon View Post
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 View Post
I can't find anything on this subject except
Depends on what terms you search for. Just being curious what did you use?
 
  


Reply

Tags
blocking


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Squid not blocking websites bittus Linux - Newbie 4 11-04-2009 03:10 AM
Blocking websites valdez_42 Linux - Newbie 6 06-28-2009 11:01 PM
blocking websites with squid tariq07 Linux - Security 2 03-03-2007 02:39 AM
blocking websites fakie_flip Linux - Software 7 09-02-2006 07:57 PM
linblock blocking websites synaptical Linux - Software 3 09-07-2004 11:12 PM


All times are GMT -5. The time now is 04:45 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration