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.


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

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