在 Synology NAS 上设置 iptables 时发生 fail2ban 错误

在 Synology NAS 上设置 iptables 时发生 fail2ban 错误

我在 Synology NAS 上设置了 fail2ban 0.9.1 来处理失败的 SSH 尝试。当我启动 jail 时,我在 fail2ban.log 中收到以下错误:

2015-02-01 17:22:52,394 fail2ban.jail           [30576]: INFO    Jail 'ssh-iptables-syno' started
2015-02-01 17:22:53,287 fail2ban.actions        [30576]: NOTICE  [ssh-iptables-syno] Ban 103.41.124.52
2015-02-01 17:22:53,613 fail2ban.action         [30576]: ERROR   iptables -I f2b-ssh-iptables-syno 1 -s 103.41.124.52 -j REJECT --reject-with icmp-port-unreachable -- stdout: ''
2015-02-01 17:22:53,625 fail2ban.action         [30576]: ERROR   iptables -I f2b-ssh-iptables-syno 1 -s 103.41.124.52 -j REJECT --reject-with icmp-port-unreachable -- stderr: 'iptables v1.4.21: unknown option "--reject-with"\nTry `iptables -h\' or \'iptables --help\' for more information.\n'
2015-02-01 17:22:53,626 fail2ban.action         [30576]: ERROR   iptables -I f2b-ssh-iptables-syno 1 -s 103.41.124.52 -j REJECT --reject-with icmp-port-unreachable -- returned 2

另一个例子:

2015-02-01 17:22:54,525 fail2ban.actions        [30576]: NOTICE  [ssh-iptables-syno] Ban 222.161.4.147
2015-02-01 17:22:54,855 fail2ban.action         [30576]: ERROR   iptables -I f2b-ssh-iptables-syno 1 -s 222.161.4.147 -j REJECT --reject-with icmp-port-unreachable -- stdout: ''
2015-02-01 17:22:54,857 fail2ban.action         [30576]: ERROR   iptables -I f2b-ssh-iptables-syno 1 -s 222.161.4.147 -j REJECT --reject-with icmp-port-unreachable -- stderr: 'iptables v1.4.21: unknown option "--reject-with"\nTry `iptables -h\' or \'iptables --help\' for more information.\n'
2015-02-01 17:22:54,858 fail2ban.action         [30576]: ERROR   iptables -I f2b-ssh-iptables-syno 1 -s 222.161.4.147 -j REJECT --reject-with icmp-port-unreachable -- returned 2
2015-02-01 17:22:54,860 fail2ban.actions        [30576]: ERROR   Failed to execute ban jail 'ssh-iptables-syno' action 'iptables-multiport' info 'CallingMap({'ipjailmatches': <function <lambda> at 0x40dfe0b0>, 'matches': u'warning\t2015/02/01 17:14:04\tSYSTEM:\tUser [root] from [222.161.4.147] failed to log in via [SSH] due to authorization failure.\nwarning\t2015/02/01 17:14:06\tSYSTEM:\tUser [root] from [222.161.4.147] failed to log in via [SSH] due to authorization failure.\nwarning\t2015/02/01 17:14:09\tSYSTEM:\tUser [root] from [222.161.4.147] failed to log in via [SSH] due to authorization failure.', 'ip': '222.161.4.147', 'ipmatches': <function <lambda> at 0x40dfe0f0>, 'ipfailures': <function <lambda> at 0x40dfe030>, 'time': 1422807774.52478, 'failures': 3, 'ipjailfailures': <function <lambda> at 0x40dfe070>})': Error banning 222.161.4.147

-> 完整日志摘录:http://pastebin.com/TvTG3c7W

当我尝试直接执行 iptables 命令时,出现以下错误:

# iptables -I f2b-ssh-iptables-syno 1 -s 222.161.4.147 -j REJECT --reject-with icmp-port-unreachable
iptables v1.4.21: unknown option "--reject-with"

我有另一台机器(12.04),装有 iptables 1.4.21 和 fail2ban 0.9.1,一切运行正常。以下是两台机器的一些 iptables 信息:

坏机器:

# iptables --version
iptables v1.4.21

# cat /proc/net/ip_tables_targets
LOG
ERROR

# cat /proc/net/ip_tables_matches
limit
state
udplite
udp
tcp
multiport
multiport
icmp

好机器:

# iptables --version
iptables v1.4.21

# cat /proc/net/ip_tables_targets
AUDIT
NFLOG
NFQUEUE
NFQUEUE
NFQUEUE
CLASSIFY
CONNMARK
CONNMARK
MARK
MARK
MARK
ULOG
TPROXY
TPROXY
MASQUERADE
REDIRECT
TOS
TOS
DSCP
LOG
TCPMSS
DNAT
SNAT
REJECT
ERROR

# cat /proc/net/ip_tables_matches
statistic
time
connlimit
realm
pkttype
connmark
connmark
physdev
string
string
owner
comment
conntrack
conntrack
conntrack
helper
limit
hashlimit
hashlimit
iprange
iprange
policy
owner
addrtype
addrtype
recent
state
length
ttl
tcpmss
multiport
multiport
tos
tos
dscp
icmp
udplite
udp
tcp

关于如何解决这个错误有什么想法吗?

更新 感谢@ricardo,我发现我的 Synology (DSM 5) 上的 iptables 缺少 REJECT 目标。但不知道如何添加它。

答案1

尝试查看好机器上加载了哪些 iptables 模块,并将它们与坏机器进行比较:

# cat /proc/net/ip_tables_matches
state
icmp
recent
multiport
multiport
udplite
udp
tcp

还检查 REJECT 目标是否存在:

# cat /proc/net/ip_tables_targets

REJECT
MASQUERADE
DNAT
SNAT
ERROR

如果您在列表中没有看到 REJECT,则表示您的 iptables 版本没有它,并且 fail2ban 规则将无法与其交互。

答案2

好的,我明白了:

fail2ban 尝试使用 iptable REJECT 目标插入禁令,但 Synology DSM5.x 系统上没有此功能。(感谢@Ricardo)

解决方案是编辑 fail2ban 操作并将其从 REJECT 更改为 DROP(默认情况下可用)。 在我的例子中(fail2ban v0.8.14,操作:iptables-allports),这将按如下方式实现:

  1. 创建本地 iptables blocktype 配置文件
  2. 将那里的块类型设置为 DROP
  3. 重新加载 fail2ban 配置

作为命令:

# echo "blocktype = DROP" > /etc/fail2ban/action.d/iptables-blocktype.local
# fail2ban-client reload

iptables-blocktype.local 由 action.d/iptables-blocktype.conf 自动加载。

德国 Synology 论坛上的这篇文章非常有帮助:http://www.synology-forum.de/showthread.html?50964-Zarafa-mit-fail2ban-absichern&highlight=fail2ban

相关内容