我几乎不想为此提交一个话题,但我还没有能够自己解决这个问题。我正在运行Federoa 17服务器,我试图通过rsyslog将丢弃的数据包从iptables记录到一个单独的日志文件中,但它会继续将它们发送到/ var / log / messages。
我的防火墙脚本中的代码段:
#!/bin/bash
iptables -F
# My accepted rules would be here
iptables -A INPUT -j LOG --log-prefix "iptables: "
iptables -A FORWARD -j LOG --log-prefix "iptables: "
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables-save > /etc/sysconfig/iptables
service iptables restart
iptables -L -v
应该从iptables捕获消息的配置文件:
[root@fc17 ]# cat /etc/rsyslog.d/iptables.conf
:msg, startswith, "iptables: " /var/log/iptables.log
& ~
我的rsyslog.conf文件中的代码段:
#### GLOBAL DIRECTIVES ####
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
#### RULES ####
# I put this in here too to see if it would work; it doesn't
:msg, startswith, "iptables: " /var/log/iptables.log
& ~
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
自从进行更改后,我已多次重启iptables和rsyslog,无论如何,它只会将丢弃的数据包从iptables记录到/ var / log / messages。
我听说在兼容模式下运行rsyslog会导致各种问题。这可能是这种情况吗?以下是我系统上的运行选项:
[root@fc17 ]# ps -ef | grep rsyslog
root 3571 1 0 00:59 ? 00:00:00 /sbin/rsyslogd -n -c 5
答案 0 :(得分:2)
startswith
比较运算符无效,因为msg
在检查我的日志时没有以iptables:
开头。
[root@localhost ~]# cat /etc/rsyslog.d/test.conf
:msg, startswith, "iptables:" /var/log/iptables.log
但是contains
比较运算符在我的FC18上工作
[root@localhost ~]# cat /etc/rsyslog.d/test.conf
:msg, contains, "iptables:" /var/log/iptables.log
参考:Rsyslog site
答案 1 :(得分:1)
你应该在" /etc/rsyslogd.conf"中添加以下两行;在指令部分
$klogParseKernelTimestamp on
$klogKeepKernelTimestamp off
这将删除每个内核消息开头出现的内核时间戳,例如" [6448.546951]"在以下日志中
Mar 31 14:36:14 localhost kernel: [ 6448.546951] iptables: IN=ppp0 OUT= MAC= SRC=
答案 2 :(得分:0)
2019解决方案。在Ubuntu18.04上使用rsyslogd 8.32.0进行了测试。
您仍然可以使用startswith
,
[root@localhost ~]# cat /etc/rsyslog.d/test.conf
:msg, startswith, " iptables:" /var/log/iptables.log
通过更改/etc/rsyslogd.conf
module(load="imklog" ParseKernelTimestamp="on" KeepKernelTimestamp="off")
答案 3 :(得分:-1)
我使用rsyslogd 5.8.10超过centos 6,我的日志报告以这种方式显示:
Aug 12 11:50:41 node2 kernel: [10256396.525411] IPTables-Dropped: IN=eth0 OUT= MAC=00:25:90:c3:05:40:00:24:13:10:8c:00:08:00 SRC=212.237.40.56 DST=37.153.1.29 LEN=45 TOS=0x00 PREC=0x00 TTL=244 ID=54321 PROTO=UDP SPT=45661 DPT=53413 LEN=25
我尝试用以下内容禁用时间戳:
$klogParseKernelTimestamp on
$klogKeepKernelTimestamp off
但是显示:
8月12日11:50:22 node2 rsyslogd-3003:无效或未知的配置文件命令 - 您忘记加载模块吗? [尝试http://www.rsyslog.com/e/3003]
在模块中有这个:
#### MODULES ####
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
#$ModLoad immark # provides --MARK-- message capability
谢谢你提前。