LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-06-2012, 05:44 PM   #1
sabresong
Member
 
Registered: Feb 2011
Location: Asheville, NC, USA
Distribution: Fedora 19
Posts: 35
Blog Entries: 1

Rep: Reputation: 2
Hosts file not blocking access to websites


I'm trying to block a group of web sites. I made the blocklist, and copied it to /etc/hosts. It didn't work. I tried both

ALL: domain.com

And

127.0.0.1 domain.com

I've checked /home and /usr recursively for local hosts files, cleared the browser cache and history, logged out and tried again. Still doesn't work. Is there something else I should be doing?

Last edited by sabresong; 01-08-2012 at 12:59 PM.
 
Old 01-06-2012, 06:13 PM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Hi there,

Quote:
Originally Posted by sabresong View Post
I'm trying to block a group of web sites. I made the blocklist, and copied it to /etc/hosts. It didn't work. I tried both

ALL: domain.com
I assume "ALL" is a placeholder, but still, the colon is wrong in the hosts file. So the entry is ignored.

Quote:
Originally Posted by sabresong View Post
127.0.0.1 domain.com
Watch out: Some Linux distros insist on having a tab character between IP and host name, not just a blank. Apart from that, this looks okay.
Bear in mind, however, that example.org and www.example.org are different host names that would need two separate entries in the hosts file. There's no wildcard scheme.

[X] Doc CPU
 
Old 01-06-2012, 06:19 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I think you misunderstand the purpose of /etc/hosts. It is used by TCP/IP as a static name lookup, for the same purpose as DNS lookups.
It isn't clear whether you are trying to block access to your web server, or whether you are trying to block web clients (browsers) from accessing specified servers. In either case, you probably want to use iptables rules to DROP traffic based on the IP(s).

Please clarify your intent.

--- rod.
 
Old 01-07-2012, 12:17 PM   #4
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, Fedora, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, Vsido, tinycore, Q4OS
Posts: 2,367

Rep: Reputation: 957Reputation: 957Reputation: 957Reputation: 957Reputation: 957Reputation: 957Reputation: 957Reputation: 957
I think you missed the point "the"

I have used this method for loading up the host files with the loopback address for resolving names of hosts that I wanted NOTHING on my machine to be able to address.

127.0.0.1 hostname.domain.net

is the correct format, no ':' involved.

PRoblem 1: you need to specify EVERY HOST not just the domain. For domain blocking you would use iptables.

Problem 2: if your host resolution configuration uses DNS first, the hosts file is the LAST place resolving names. If you want it to be the first, you need to make sure resolution is checked in teh proper order (hosts first, then DNS). That is usually set in the host.conf file, usually found under /etc.

Check your hosts.conf file and correct as needed, then let us know the result.
 
Old 01-08-2012, 01:06 PM   #5
sabresong
Member
 
Registered: Feb 2011
Location: Asheville, NC, USA
Distribution: Fedora 19
Posts: 35
Blog Entries: 1

Original Poster
Rep: Reputation: 2
I didn't know about domain.com and www.domain.com being two separate things. I was trying to block access to specific websites during working hours. It's working fine now by using both domain.com and www.domain.com in the hosts file. Thanks for the help.
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Blocking websites via /etc/hosts Deewanagan Linux - Networking 15 12-13-2009 02:13 PM
LXer: 'hall of shame' blasts websites blocking surfer access LXer Syndicated Linux News 0 01-01-2007 05:21 AM
Multi-Websites Hosted with /etc/hosts File? mpapet Linux - Networking 2 11-13-2006 03:48 PM
blocking specific websites, but allowing internet access poiuytrewq Linux - General 6 09-01-2006 12:45 AM
Blocking access to specific Websites and IP Ports fieldyweb Linux - Newbie 3 12-02-2005 06:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration