大网数据广告活动
服务器运维问答

Cloudflare behind site iptables not blocking HTTP and HTTPS ports

· 52CE 我爱测

When the Fail2ban trigger an IP ban action, I want to block all the ports on my Ubuntu Server. Right now, I use banaction = iptables-allports and CSF. At this moment it only blocked SSH port, even if I use iptables-allports in fa…

问题原文

原帖链接 · Chathu · CC BY-SA 4.0

When the Fail2ban trigger an IP ban action, I want to block all the ports on my Ubuntu Server. Right now, I use banaction = iptables-allports and CSF. At this moment it only blocked SSH port, even if I use iptables-allports in fail2ban.

I face this issue sites behind the Cloudflare reverse proxy.

This is an Ubuntu 18.04 Nginx server. I can view visitors IP address in nginx log files. So I believe this VPS X-Forwarded-For in nginx configuration working as expected.

When I manually added an IP address to the CSF temporary ban list via SSH, now it again not blocked HTTP and HTTPS ports. This server support IPv4 and IPv6.

When I search the blocked IP it shows following outcome.

root@server:~# csf -g 43.250.242.xxx

Table  Chain            num   pkts bytes target     prot opt in     out     source               destination

filter TOR              174     22  1320 REJECT     all  --  *      *       43.250.242.xxx       0.0.0.0/0            reject-with icmp-port-unreachable
filter TOR              2        0     0 REJECT     all  --  *      *       43.250.242.xxx       0.0.0.0/0            reject-with icmp-port-unreachable
filter TOR              6        0     0 REJECT     all  --  *      *       43.250.242.xxx       0.0.0.0/0            reject-with icmp-port-unreachable


IPSET: Set:cc_lk Match:43.250.242.xxx Setting:CC_ALLOW_PORTS Country:LK


ip6tables:

Table  Chain            num   pkts bytes target     prot opt in     out     source               destination
No matches found for 43.250.242.xxx in ip6tables

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

You can't block these connections in iptables, because those IP addresses do not connect to your server. Instead, they connect to CloudFlare, and CloudFlare connects to your server. Because of this, iptables can only see the CloudFlare IP addresses.

Instead, you need to use IP address controls provided by your web server software or by CloudFlare.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-08-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。