Ubuntu iptables 日志不会记录到任何日志文件

Ubuntu iptables 日志不会记录到任何日志文件

我尝试将日志放入 iptables 中,但在任何文件中都找不到任何日志。虽然当我运行 dmesg 命令时,我可以看到 iptables 条目。但相同的条目不会进入任何日志文件。这是我的 iptables 规则:

/sbin/iptables -I INPUT 1 -p tcp  -j LOG --log-level info --log-prefix " [ IPTABLES " --log-uid 

这是 syslog.conf 文件:

#  /etc/syslog.conf Configuration file for syslogd.
#
#           For more information see syslog.conf(5)
#           manpage.

#
# First some standard logfiles.  Log by facility.
#

auth,authpriv.*      -/var/log/auth.log
*.*;auth,authpriv.none      -/var/log/syslog
#cron.*          -/var/log/cron.log
daemon.*            -/var/log/daemon.log
kern.*              -/var/log/kern.log
lpr.*               -/var/log/lpr.log
mail.*              -/var/log/mail.log
user.*              -/var/log/user.log

#
# Logging for the mail system.  Split it up so that
# it is easy to write scripts to parse these files.
#
mail.info           -/var/log/mail.info
mail.warn           -/var/log/mail.warn
mail.err         -/var/log/mail.err

# Logging for INN news system
#
news.crit        -/var/log/news/news.crit
news.err         -/var/log/news/news.err
news.notice         -/var/log/news/news.notice

#
# Some `catch-all' logfiles.
#
*.=debug;\
    auth,authpriv.none;\
    news.none;mail.none -/var/log/debug
*.=info;*.=notice;*.=warn;\
    auth,authpriv.none;\
    cron,daemon.none;\
    mail,news.none      -/var/log/messages

#
# Emergencies are sent to everybody logged in.
#
*.emerg             *

#
# I like to have messages displayed on the console, but only on a virtual
# console I usually leave idle.
#
#daemon,mail.*;\
#   news.=crit;news.=err;news.=notice;\
#   *.=debug;*.=info;\
#   *.=notice;*.=warn   /dev/tty8

# The named pipe /dev/xconsole is for the `xconsole' utility.  To use it,
# you must invoke `xconsole' with the `-file' option:
#
#    $ xconsole -file /dev/xconsole [...]
#
# NOTE: adjust the list below, or you'll go crazy if you have a reasonably
#      busy site..
#
daemon.*;mail.*;\
    news.err;\
    *.=debug;*.=info;\
    *.=notice;*.=warn   -/var/log/xconsole.log

以下是更多详细信息:

root@us4839:~# ps ax | grep syslog
11336 pts/1    S+     0:00 grep syslog
17910 ?        Ss     0:00 /sbin/syslogd
root@us4839:~#
root@us4839:~#
root@us4839:~# lsof /var/log/syslog
COMMAND   PID USER   FD   TYPE DEVICE SIZE     NODE NAME
syslogd 17910 root    2w   REG   0,42 5508 57114744 /var/log/syslog
root@us4839:~#

我是否按照这条规则做错了什么,或者其他地方出了问题?

答案1

我很久以前遇到过类似的问题,它(部分)与 OpenVZ 架构有关。

您能否确认:

  • iptables 规则语法正确
  • syslog 和 klogd 正在运行(据我所知,openVZ 需要 klogd 才能正确记录内核消息)

消息输出是否包含 iptables 日志行?如果是,那么这可能是 syslog 配置问题。您可以尝试添加一条指令,将 kernel.warn 放在单独的 iptables.log 文件中。

编辑 您是否手动检查了日志文件?如果是,我会使用 grep 来查找它,例如

grep -rl "MAC" /var/log/*   # should match, else use the interface name or IPTABLES as pattern

只想确认一下...

相关内容