Skip to content

Instantly share code, notes, and snippets.

@ShortyDev
Created March 4, 2022 21:39
Show Gist options
  • Save ShortyDev/1fb19d2968c1ee3f68f43ee1fa0d7cfa to your computer and use it in GitHub Desktop.
Save ShortyDev/1fb19d2968c1ee3f68f43ee1fa0d7cfa to your computer and use it in GitHub Desktop.
iptables -D INPUT -j cloudflare
iptables -F cloudflare
iptables -N cloudflare
iptables -A INPUT -j cloudflare
ip6tables -D INPUT -j cloudflare
ip6tables -F cloudflare
ip6tables -N cloudflare
ip6tables -A INPUT -j cloudflare
for i in `curl https://www.cloudflare.com/ips-v4 -L`; do iptables -I cloudflare -p tcp -m multiport --dports http,https -s $i -j ACCEPT; done
for i in `curl https://www.cloudflare.com/ips-v6 -L`; do ip6tables -I cloudflare -p tcp -m multiport --dports http,https -s $i -j ACCEPT; done
iptables -A cloudflare -p tcp -m multiport --dports http,https -j DROP
ip6tables -A cloudflare -p tcp -m multiport --dports http,https -j DROP
@ShortyDev
Copy link
Author

For blocking other ports except 80 (http) and 443 (https), you can just add/replace protocols on the iptables command.
Example:
--dports http,https,1337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment