Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.
Hey guys,

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 next to the " localhost" statement.

Now, if I type 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 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?

share|improve this question

migrated from Feb 14 '10 at 16:20

This question came from our site for professional and enthusiast programmers.

Not programming-related ? –  Paul Feb 14 '10 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 '10 at 16:19
superuser, perhaps? –  luiscubal Feb 14 '10 at 16:20
I'm going to assume the downvote was because it was asked on I upvoted because it is a useful question with lots of uses on Linux workstations. –  Paul Kroon Feb 14 '10 at 17:11

4 Answers 4

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 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -d -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 -j DROP
share|improve this answer

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

share|improve this answer

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.

share|improve this answer

(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.


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

iptables -A OUTPUT -p tcp --dport 80 -d -j DROP
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.