LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-01-2007, 11:29 PM   #1
RodWC
Member
 
Registered: Oct 2005
Distribution: SolydK, Linux Mint KDE, Debian
Posts: 180

Rep: Reputation: 30
Need help with blocking sites/editing Hosts file


Hi everyone. I have a friend who needs porn blocking on his computer, and I think editing the hosts file will be the simplest thing at this point (unless you all have better suggestions. Tried squid, complicated and did not work with a large domains file). I'd like to take the domains file I downloaded for squid and add it to the hosts file, but I would need to add 127.0.0.1 to the beginning of each line. I know there must be a simple low level command for doing this, but what is it?

Thanks for any help or alternative suggestions.

Also, is there a way to protect the hosts file so that even someone with the root password can not edit it? This wouldn't be entirely necessary but would be very useful.

Last edited by RodWC; 05-01-2007 at 11:34 PM.
 
Old 05-02-2007, 12:00 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
You could make it harder for someone to edit by changing it to be read-only. But the idea behind root is that they can do anything.

Try a command like this to append the 127.0.0.1 you need and add the entries to /etc/hosts:
Code:
sed 's/^/127.0.0.1 /' HOSTSFILE >> /etc/hosts
 
Old 05-02-2007, 12:02 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If the file consists of only domain addresses, then you could use sed to edit the file:
sed 's/^/127.0.0.1/' filename >newfilename

A very long linear list increases the time time to search proportionally to the length of the list.

Whatever you do to protect the /etc/hosts file can be undone by root. It would be a better solution if the only access to the internet is through a gateway device or computer that is physically locked up.
 
Old 05-02-2007, 07:01 AM   #4
RodWC
Member
 
Registered: Oct 2005
Distribution: SolydK, Linux Mint KDE, Debian
Posts: 180

Original Poster
Rep: Reputation: 30
Thanks guys! If I were to make the Internet come through a computer as a gateway, would editing the hosts file on the gateway computer be sufficient?
 
Old 05-02-2007, 07:47 AM   #5
RodWC
Member
 
Registered: Oct 2005
Distribution: SolydK, Linux Mint KDE, Debian
Posts: 180

Original Poster
Rep: Reputation: 30
now I seem to have another problem . . . The information in the hosts file is entered as such:

127.0.0.1 badsite.com
127.0.0.1 badsite2.com


And so on. The problem is, it's not working. Is it possible for the hosts file to be too big (how about 17Mb)?
 
Old 05-02-2007, 08:38 AM   #6
RodWC
Member
 
Registered: Oct 2005
Distribution: SolydK, Linux Mint KDE, Debian
Posts: 180

Original Poster
Rep: Reputation: 30
His DSL ISP, Embarq, has it's own blocking service, but it only has software for Windows. Supposedly this software makes so the computer uses blocking through the ISP itself. Would there be a way to access their 'restricted' server from Linux and block other access? The program is called fsecure. They were unable to get it running through Wine.

Last edited by RodWC; 05-02-2007 at 08:40 AM.
 
Old 05-02-2007, 02:14 PM   #7
RodWC
Member
 
Registered: Oct 2005
Distribution: SolydK, Linux Mint KDE, Debian
Posts: 180

Original Poster
Rep: Reputation: 30
Okay I figured it out. It must be written like www.google.com instead of google.com, so I ran the sed command twice. Once to add the 127.0.0.1 and the second time to add '127.0.0.1 www.' so I now have over twice the file size (40Mb!) but that seems to be working. Thanks for the help.

Of course there is still the issue of root access.
 
Old 05-02-2007, 02:17 PM   #8
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Why are you trying to limit root's access to the file?
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
blocking windows update sites ilnli Linux - Security 1 09-20-2006 01:30 AM
iptables is blocking sites... The_wave Linux - Networking 9 09-09-2005 04:44 PM
Blocking some sites... gani *BSD 2 11-05-2004 09:07 PM
Blocking porn sites debug019 Linux - Newbie 4 09-07-2004 01:13 AM
Blocking web sites lovswr Linux - Software 6 11-03-2003 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:04 AM.

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
Open Source Consulting | Domain Registration