我刚刚在我的Centos反向代理服务器上完成了fail2ban的设置。 我能够得到它阻止所有要求,如果一定的标准得到满足(非常简单)。
但是,现在我想redirect违规用户,而不是阻止他们。 我知道这是可能的使用自定义操作文件,但我似乎无法让它正常工作。 我想redirect到服务器上的另一个端口(也许运行Apache与一个自定义的网页,说明为什么他们被redirect)或完全到另一个网站。
有什么想法吗? 这是我尝试redirect到另一个端口(意图是将违规用户redirect到同一台服务器上的端口8080)。 该操作称为防火墙redirect,它来自firewallcmd-ipset。
# Fail2Ban action file for firewall-cmd/ipset # # This requires: # ipset (package: ipset) # firewall-cmd (package: firewalld) # # This is for ipset protocol 6 (and hopefully later) (ipset v6.14). # Use ipset -V to see the protocol and version. # # IPset was a feature introduced in the linux kernel 2.6.39 and 3.0.0 kernels. # # If you are running on an older kernel you make need to patch in external # modules. [INCLUDES] before = iptables-common.conf [Definition] actionstart = ipset create fail2ban-<name> hash:ip timeout <bantime> firewall-cmd --add-forward-port=port=443:proto=tcp:toport=8080 -m set --match-set fail2ban-<name> src actionstop = firewall-cmd --remove-forward-port=port=443:proto=tcp:toport=8080 -m set --match-set fail2ban-<name> src ipset flush fail2ban-<name> ipset destroy fail2ban-<name> actionban = ipset add fail2ban-<name> <ip> timeout <bantime> -exist actionunban = ipset del fail2ban-<name> <ip> -exist [Init] # Option: chain # Notes specifies the iptables chain to which the fail2ban rules should be # added # Values: [ STRING ] # chain = INPUT_direct # Option: bantime # Notes: specifies the bantime in seconds (handled internally rather than by fail2ban) # Values: [ NUM ] Default: 600 bantime = 600 # DEV NOTES: # # Author: Edgar Hoch and Daniel Black # firewallcmd-new / iptables-ipset-proto6 combined for maximium goodness
另外,这里是我在fail2ban.log文件中看到的错误的一个片段。 我明白这是错误的,我只是不知道如何正确地解决它。 🙂
2015-06-01 09:49:05,548 fail2ban.action [11334]: ERROR ipset create fail2ban-apache-gpd_flood hash:ip timeout 3600 firewall-cmd --add-forward-port=port=443:proto=tcp:toport=8080 -m set --match-set fail2ban-apache-gpd_flood src -- stdout: '' 2015-06-01 09:49:05,548 fail2ban.action [11334]: ERROR ipset create fail2ban-apache-gpd_flood hash:ip timeout 3600 firewall-cmd --add-forward-port=port=443:proto=tcp:toport=8080 -m set --match-set fail2ban-apache-gpd_flood src -- stderr: 'usage: see firewall-cmd man page\nfirewall-cmd: error: unrecognized arguments: -m set --match-set fail2ban-apache-gpd_flood src\n' 2015-06-01 09:49:05,549 fail2ban.action [11334]: ERROR ipset create fail2ban-apache-gpd_flood hash:ip timeout 3600 firewall-cmd --add-forward-port=port=443:proto=tcp:toport=8080 -m set --match-set fail2ban-apache-gpd_flood src -- returned 2 2015-06-01 09:49:05,549 fail2ban.actions [11334]: ERROR Failed to start jail 'apache-gpd_flood' action 'firewallcmd-redirect': Error starting action
提前致谢!
我不确定,但这是我的build议:
在这里 ,ipset并不总是与fail2ban一起安装。 你可以请检查你是否安装了ipset?
https://serverfault.com/a/671839/118677的答案build议使用iptables而不是firewalld。 如果你这样做,你可以重写为:
iptables -t nat -A PREROUTING -i eth0 -p tcp -s bannedip --dport 443 -j REDIRECT --to-port 8080
和actionunban一样:
iptables -t nat -D PREROUTING -i eth0 -p tcp -s bannedip --dport 443 -j REDIRECT --to-port 8080
(见这里 )。
你的禁令(3600)目前与configuration的Init部分中的bantime不匹配。 参见决斗fail2ban和ipset超时 。