1

I was looking for a simple and effective way to block websites and I really like this simple soultion.

The problem is, you can block facebook with this modification:

0.0.0.1 facebook.com    
0.0.0.1 www.facebook.com

but users can still access facebook by going to fr-fr.facebook.com or other prefix+website combinations.

My question is, is there any way to include all possible prefixes? Virtually speaking, some patterns like *.facebook.com

Zanna
  • 70,465
Sadegh
  • 1,105
  • The /etc/hosts way is quite hacky (also because you need superuser privileges for it) but I think you could append 0.0.0.0 *.facebook.com to the file and that would work. See here for a full list of Facebook domains. – grooveplex Jul 13 '16 at 10:53
  • it is not working! but tnx anyways – Sadegh Jul 13 '16 at 10:54
  • Well, I use facebook as an example. I need to block many websites and try to find a solution for it ... – Sadegh Jul 13 '16 at 10:56

1 Answers1

0

This can be done by configuring your firewall to block traffic in/out.

The network ranges in use by Facebook, which is your example turns out to be four subnets ( I've used whois to get them , there are many other methods ..)

31.13.64.0/18 
66.220.144.0/20
69.171.224.0/19
69.63.176.0/20

You can filter out those addresses by using UFW OR iptables so if you have UFW installed run :

sudo ufw reject out to 31.13.64.0/18 
sudo ufw reject out to 66.220.144.0/20 
sudo ufw reject out to 69.171.224.0/19 
sudo ufw reject out to 69.63.176.0/20 

Else you can install it with sudo apt-get install ufw or just use directly iptables by running those commands with root access:

iptables -A OUTPUT -d 31.13.64.0/18 -j REJECT 
iptables -A OUTPUT -d 66.220.144.0/20 -j REJECT 
iptables -A OUTPUT -d 69.171.224.0/19 -j REJECT 
iptables -A OUTPUT -d 69.63.176.0/20 -j REJECT 
storm
  • 4,973
  • Can you add the exact command line of whois ? – Sadegh Jul 13 '16 at 11:03
  • 1
    first install with sudo apt-get install whois then whois facebook.com and read the output you'll get all facebook servers IPs .. I don't know if there is a better method to get the IPs though . – storm Jul 13 '16 at 11:06
  • Do you know why there are also godaddy.com and google.com in the output of whois? isn't there a risk to block google with this method?! – Sadegh Jul 13 '16 at 11:11
  • Those godaddy.com and google.com are registrars .. a registrar is a server that register whois info .. there are no risk to block them – storm Jul 13 '16 at 13:02