我正在使用 CloudflareIPv4和IPv6列表以阻止来自不属于 Cloudflare 的任何 IP 到我的服务器的所有连接。
当我sudo ufw status
在服务器上运行时,我得到:
Status: active
To Action From
-- ------ ----
80,443/tcp ALLOW 173.245.48.0/20 # Cloudflare IP
80,443/tcp ALLOW 103.21.244.0/22 # Cloudflare IP
80,443/tcp ALLOW 103.22.200.0/22 # Cloudflare IP
80,443/tcp ALLOW 103.31.4.0/22 # Cloudflare IP
80,443/tcp ALLOW 141.101.64.0/18 # Cloudflare IP
80,443/tcp ALLOW 108.162.192.0/18 # Cloudflare IP
80,443/tcp ALLOW 190.93.240.0/20 # Cloudflare IP
80,443/tcp ALLOW 188.114.96.0/20 # Cloudflare IP
80,443/tcp ALLOW 197.234.240.0/22 # Cloudflare IP
80,443/tcp ALLOW 198.41.128.0/17 # Cloudflare IP
80,443/tcp ALLOW 162.158.0.0/15 # Cloudflare IP
80,443/tcp ALLOW 104.16.0.0/13 # Cloudflare IP
80,443/tcp ALLOW 104.24.0.0/14 # Cloudflare IP
80,443/tcp ALLOW 172.64.0.0/13 # Cloudflare IP
80,443/tcp ALLOW 131.0.72.0/22 # Cloudflare IP
80,443/tcp ALLOW 2400:cb00::/32 # Cloudflare IP
80,443/tcp ALLOW 2606:4700::/32 # Cloudflare IP
80,443/tcp ALLOW 2803:f800::/32 # Cloudflare IP
80,443/tcp ALLOW 2405:b500::/32 # Cloudflare IP
80,443/tcp ALLOW 2405:8100::/32 # Cloudflare IP
80,443/tcp ALLOW 2a06:98c0::/29 # Cloudflare IP
80,443/tcp ALLOW 2c0f:f248::/32 # Cloudflare IP
但是当我telnet xxx.xxx.xxx.xxx 80
从本地计算机(xxx.xxx.xxx.xxx 服务器的 IP)运行时,我得到:
Trying xxx.xxx.xxx.xxx...
Connected xxx.xxx.xxx.xxx.
所以,看起来我没有被阻止,而我应该被阻止,因为我的本地 IP 没有列出。难道我做错了什么?
更新1:
我部署了另一台服务器只是为了进行相同的测试并确保我的 IP 不在白名单中。结果是一样的。
更新2:
如果我这样做,tracepath xxx.xxx.xxx.xxx
我会得到类似的信息(IP 和域名受到谴责):
1?: [LOCALHOST] pmtu 1472
1: <MyComputerName>.mshome.net 0.576ms
1: <MyComputerName>.mshome.net 0.365ms
2: 10.0.0.1 0.790ms
3: my.isp.provider.com 8.934ms
4: <My.Public.IP.Address> 9.595ms asymm 5
5: no reply
6: an.isp.that.i.dont.know.com 33.937ms
7: same.isp.that.i.dont.know.com 46.866ms asymm 6
8: the.isp.that.i.dont.know.com 45.673ms asymm 5
9: <IP.Owned.By.Cloud.My.Provider> 42.138ms asymm 7
10: no reply
11: no reply
12: no reply
13: no reply
14: no reply
15: no reply
16: no reply
17: no reply
18: no reply
19: no reply
20: no reply
21: no reply
22: no reply
23: no reply
24: no reply
25: no reply
26: no reply
27: no reply
28: no reply
29: no reply
30: no reply
Too many hops: pmtu 1472
Resume: pmtu 1472
答案1
我建议使用 Cloudflare Authenticated Pull,而不是 IP 锁定您的服务器。
由于您无法保证 IP 保持不变,因此您还需要运行 cronjob 从 cloudlfare 获取 IP 并更新防火墙。另外,如果我知道您的原始 IP,我仍然可以通过我自己的 cloudflare 站点连接其 dns。这将很容易地破坏 IP 白名单的安全措施。
您可以在 Cloudflare 的开发人员文档中找到有关经过身份验证的拉取的信息: https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull/
答案2
问题是 Docker 打开了暴露的端口,但它们没有显示在 UFW 中。抱歉我没有提到 Docker。我无法想象它与它有关。
请参阅此线程:https://serverfault.com/questions/962012/ufw-not-blocking-incoming-traffic