iptables通过syslog-nglogging到不同的文件

我在我的iptables和syslog文件中有以下configuration:

IPTABLES

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m tcp --dport 222 -j ACCEPT -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT -A INPUT -j DROP -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 

SYSLOG-NG

 destination d_iptables { file("/var/log/iptables/iptables.log"); }; filter f_iptables { facility(kern) and match("IN=" value("MESSAGE")) and match("OUT=" value("MESSAGE")); }; filter f_messages { level(info,notice,warn) and not facility(auth,authpriv,cron,daemon,mail,news) and not filter(f_iptables); }; log { source(s_src); filter(f_iptables); destination(d_iptables); };` 

我重新启动syslog-ng,日志不写入。

你的syslog-ngconfiguration对我来说看起来不错,但你的iptablesconfiguration不是。 -j LOG行显示在DROP的所有行之后,因此永远不会到达。

您应该将LOG行直接移到您想要logging的事件之前。 如果你想logging一切,先把它放。 如果你想logging所有不被接受的东西,把它放在所有的ACCEPT之后。

好吧,经过很多痛苦,我终于搞定了,这是最后的configuration,我希望它能帮助别人。

iptables的

  :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :LOGNDROP - [0:0] :OUTPUT ACCEPT [63:18352] -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7 -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m tcp --dport 222 -j ACCEPT -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT -A INPUT -s 85.25.146.0/24 -j DROP -A INPUT -j DROP 

syslog.confg

 destination d_iptables { file("/var/log/iptables.log"); }; filter f_iptables { match("iptables denied" value("MESSAGE")); }; filter f_debug { level(debug) and not facility(auth, authpriv, news, mail) and not filter(f_iptables); }; # not facility(auth,authpriv,cron,daemon,mail,news) and not filter(f_iptables); }; filter f_kern { facility(kern) and not filter(f_iptables); }; log { source(s_src); filter(f_iptables); destination(d_iptables); };