我在 ubuntu 18.04 上运行 apache。我使用 IPtables 拒绝除 CloudFlare 范围之外的所有 IP 地址的访问,当我运行 iptables -L –line-number 时,我得到
1 ACCEPT tcp – 131.0.72.0/22 anywhere multiport dports http,https
2 ACCEPT tcp – 172.64.0.0/13 anywhere multiport dports http,https
3 ACCEPT tcp – 104.16.0.0/12 anywhere multiport dports http,https
4 ACCEPT tcp – 162.158.0.0/15 anywhere multiport dports http,https
5 ACCEPT tcp – 198.41.128.0/17 anywhere multiport dports http,https
6 ACCEPT tcp – 197.234.240.0/22 anywhere multiport dports http,https
7 ACCEPT tcp – 188.114.96.0/20 anywhere multiport dports http,https
8 ACCEPT tcp – 190.93.240.0/20 anywhere multiport dports http,https
9 ACCEPT tcp – 108.162.192.0/18 anywhere multiport dports http,https
10 ACCEPT tcp – 141.101.64.0/18 anywhere multiport dports http,https
11 ACCEPT tcp – 103.31.4.0/22 anywhere multiport dports http,https
12 ACCEPT tcp – 103.22.200.0/22 anywhere multiport dports http,https
13 ACCEPT tcp – 103.21.244.0/22 anywhere multiport dports http,https
14 ACCEPT tcp – 173.245.48.0/20 anywhere multiport dports http,https
15 ufw-before-logging-input all – anywhere anywhere
16 ufw-before-input all – anywhere anywhere
17 ufw-after-input all – anywhere anywhere
18 ufw-after-logging-input all – anywhere anywhere
19 ufw-reject-input all – anywhere anywhere
20 ufw-track-input all – anywhere anywhere
21 DROP tcp – anywhere anywhere multiport dports http,https
我运行的确切命令是:
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 173.245.48.0/20 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 103.21.244.0/22 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 103.22.200.0/22 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 103.31.4.0/22 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 141.101.64.0/18 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 108.162.192.0/18 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 190.93.240.0/20 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 188.114.96.0/20 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 197.234.240.0/22 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 198.41.128.0/17 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 162.158.0.0/15 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 104.16.0.0/12 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 172.64.0.0/13 -j ACCEPT
sudo iptables -I INPUT -p tcp -m multiport --dports http,https -s 131.0.72.0/22 -j ACCEPT
sudo iptables -A INPUT -p tcp -m multiport --dports http,https -j DROP
为什么我仍然能够从 Digitalocean droplet 的直接 IP 地址访问该网站?谢谢
编辑:
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 173.245.48.0/20 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 103.21.244.0/22 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 103.22.200.0/22 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 103.31.4.0/22 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 141.101.64.0/18 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 108.162.192.0/18 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 190.93.240.0/20 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 188.114.96.0/20 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 197.234.240.0/22 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 198.41.128.0/17 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 162.158.0.0/15 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 104.16.0.0/12 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 172.64.0.0/13 -j ACCEPT
sudo iptables -I OUTPUT -p tcp -m multiport --dports http,https -s 131.0.72.0/22 -j ACCEPT
sudo iptables -A OUTPUT -p tcp -m multiport --dports http,https -j DROP
答案1
您的链可能错误(INPUT 是针对进入您网络的流量)或者您是通过目标端口而不是源端口进行匹配的。我怀疑您想使用 OUTPUT 链而不是 INPUT 链来阻止流量离开您的 PC。
我还假设 droplet 的 IP 地址不在您明确允许的范围内。