Pages

Block twitter and facebook via iptables



The most effective way for Blocking twitter and facebook, is at firewall level thanks to iptables/ip6tables :), In this post I'll show you how to block twitter and facebook in an efficient way despite they have many ip addresses and how many times they change, the method below will works for ipv4 and ipv6

I assume you are on linux system, this won't work on others, tested on Debian 7 (Wheezy)

Programs needed

1. dig: DNS lookup utility
2. grep: print lines matching a pattern
3. sed: stream editor for filtering and transforming text
4. iptables: administration tool for IPv4 packet filtering and NAT
5. ip6tables: IPv6 packet filter administration
6. iptables-save: dump iptables rules to stdout
7. ip6tables-save: dump ip6tables rules to stdout
8. expr: evaluate expressions

How blocking works

You resolve facebook's subdomains and twitter's to get their ip addresses, then you update your iptables/ip6tables rules only if the ips are not in there, so if you run Debian as router then anybody on your network trying to connect to facebook or twitter will get a message that the server rejected the request, Since querying the DNS server won't give you all the ip addresses you want to block you MUST run the "twitter-facebook-blocker.sh" shell script(found below) periodically via cron job for example you may run it hourly by editing /etc/crontab file,  if the path of shell script file is /var/scripts/twitter-facebook-blocker.sh then you add a line like the following:

7  *  *  *  *   root /var/scripts/twitter-facebook-blocker.sh

Shell script:

I included "twitter-facebook-blocker.sh" script for your convenience, make sure you chmod the script to make it executable, please  note that this script needs to be run with root privileges .
The script is documented,  feel free to change it as you wish.

Download &Note:

This Shell script  named  "twitter-facebook-blocker.sh" comes without any warranty  of any kind, since it needs to be run as root you're aware of any consequences, so use it at your risk, check the integrity of the shell script, and do read it before you run it:

https://hotfile.com/dl/223531723/6d4377d/twitter-facebook-blocker.sh.html

checksums twitter-facebook-blocker.sh
SHA1  22c45328db314304ef6fea3b6a6a2ae16219d7f4
SHA256   5ce55cd4daf08201abaa0513ed9ea00dcada2e88123c4f0899ffa9c8640ae772
SHA512    e5d434f0b973937eaf55e9c78848b7e140c379d21a6b56aab1a2a0ccce8a35fb77810a3c52880bdfd4c85e0a477fedcabef1d5c56ad2ee1961634bc0030bb212


1 comment:

  1. hotfile is down, would you please upload it on another share like 4shared for example !

    ReplyDelete