-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhost.sh
26 lines (22 loc) · 923 Bytes
/
host.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# !/bin/bash
#
# Configure your iptables to allow IPs from Cloudflare only.
# For users whose HTTP server is directly exposed to the host 80/443.
#
# author: kingcc <[email protected]>
iptables -N cloudflare-only
ip6tables -N cloudflare-only
iptables -A INPUT -p tcp -m multiport --dports http,https -j cloudflare-only
ip6tables -A INPUT -p tcp -m multiport --dports http,https -j cloudflare-only
# https://www.cloudflare.com/ips
for i in `curl https://www.cloudflare.com/ips-v4`; do
iptables -A cloudflare-only -s $i -j RETURN;
done
for i in `curl https://www.cloudflare.com/ips-v6`; do
ip6tables -A cloudflare-only -s $i -j RETURN;
done
# Log and discard network packets
iptables -A cloudflare-only -j LOG --log-prefix "IPTABLES_CLOUDFLARE_ONLY_BANNED: "
ip6tables -A cloudflare-only -j LOG --log-prefix "IP6TABLES_CLOUDFLARE_ONLY_BANNED: "
iptables -A cloudflare-only -j DROP
ip6tables -A cloudflare-only -j DROP