Bye Bye Facebook

Blocking Facebook with Firewalld

Want to block Facebook and all of its trackers? Here’s a little script that looks up all IP addresses used by Facebook and blocks outbound connections using Firewalld.

#!/bin/bash

# Get Facebook IP range from whois.
IP=$(whois -h whois.radb.net '!gAS32934' | grep /)

# Add a firewall rule for each entry.
for ip in $IP
do
    firewall-cmd --direct --add-rule ipv4 filter OUTPUT_direct 0 -d $ip -j DROP &> /dev/null
done