4

I was trying on blocking some of the websites that I usually use even I need to work hard, e.g facebook.

I am using Ubuntu 9.10 and I tried to change the /etc/hosts file by adding www.facebook.com next to the "127.0.0.1 localhost" statement.

Now, if I type www.facebook.com to my browser, an error message appears and says "oops, the link is broken" but if I try to access to facebook by using the IP address 69.63.184.142 my browser can still access to facebook. If anyone knows a more clever way to block access to a website please reply. Thanks.

Oops, sorry one more question, can I use the iptables command in linux to ban a website? If yes, how?

4
  • Not programming-related ?
    – Paul
    Feb 14, 2010 at 16:18
  • This is more of a serverfault question, but short answer: yes you can use iptables to block traffic to facebook's IP.
    – Xorlev
    Feb 14, 2010 at 16:19
  • 1
    superuser, perhaps?
    – luiscubal
    Feb 14, 2010 at 16:20
  • I'm going to assume the downvote was because it was asked on stackoverflow.com. I upvoted because it is a useful question with lots of uses on Linux workstations.
    – Paul Kroon
    Feb 14, 2010 at 17:11

4 Answers 4

2

I did somthing similar in the past using iptables. I needed to block all sites save for two that were needed for a programming competition. The rules that did the work were these:

iptables -A OUTPUT -p tcp --dport 80 -d www.cppreference.com -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -d java.sun.com -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j DROP

Although I haven't tested it, you should be able to accomplish this with the following rule:

iptables -A OUTPUT -p tcp --dport 80 -d facebook.com -j DROP
0

you can block the ip address, but if the site has many - you need to block them all...

0

If this is for you personally, there is the LeechBlock addon for firefox that does exactly what you are asking for. Everything more general like blocking based on IP addresses gets quickly very hard to maintain.

0

(Sorry about my english)

If you can not prevent you to going sites by IP, iptables can not help you too. Because you will spent many time to know, how disable your firewall. Disabling iptables is difficult and you will spent ... spent ... spent time. But you'll disabled it. And after that you'll spent ... spent ... spent time to facebook and so on.

I suggest you - don't go to facebook.

That's all.

Simply.

P.S. If I thinked as a sys admin, I suppose this comment:

iptables -A OUTPUT -p tcp --dport 80 -d facebook.com -j DROP

You must log in to answer this question.