[SOLVED] Hosts file not blocking access to websites
Linux - NewbieThis 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!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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
I assume "ALL" is a placeholder, but still, the colon is wrong in the hosts file. So the entry is ignored.
Originally Posted by sabresong
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.
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).
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.
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.
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.