Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.