2014-03-31 41 views
3

我几乎不愿意为此提交一个主题,但我一直无法自己弄清楚。我正在运行一个Federoa 17服务器,并且我试图通过rsyslog将丢失的数据包从iptables记录到一个单独的日志文件中,但它始终将它们发送到/ var/log/messages。从我的防火墙脚本rsyslog - 基于属性的过滤不起作用

段:

#!/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的相扶消息:

从我rsyslog.conf文件
[[email protected] ]# cat /etc/rsyslog.d/iptables.conf 
:msg, startswith, "iptables: " /var/log/iptables.log 
& ~ 

段:

#### 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,并且没有遮罩r什么,它只会将从iptables丢弃的数据包记录到/ var/log/messages。

我听说在兼容模式下运行rsyslog会导致各种问题。这可能是这种情况吗?下面是我的系统上其运行选项:

[[email protected] ]# ps -ef | grep rsyslog 
root  3571  1 0 00:59 ?  00:00:00 /sbin/rsyslogd -n -c 5 

回答

2

startswith比较运营商没有工作,因为msg没有与iptables:开始时我检查我的日志。

[[email protected] ~]# cat /etc/rsyslog.d/test.conf 
:msg, startswith, "iptables:" /var/log/iptables.log 

contains比较运营商也和我一起FC18

[[email protected] ~]# cat /etc/rsyslog.d/test.conf 
:msg, contains, "iptables:" /var/log/iptables.log 

编号:Rsyslog site

+0

切换到'contains'而不是'startswith'确实有效(它也没有登录到/ var/log/messages),我现在可以肯定地离开它,但是有没有办法让'开始工作,因为它应该?有没有办法在rsyslog中看看它是如何从/etc/rsyslog.conf解析其规则的? – sirjames2004

+0

日志行形式为'Mar 31 14:36:14 localhost kernel:[6448.546951] iptables:IN = ppp0 OUT = MAC = SRC ='我认为这就是为什么'startswith'不起作用的原因。这可能会帮助你。 http://www.rsyslog.com/doc/troubleshoot.html – clement

1

你应该在指令部分

添加以下两行的 “/etc/rsyslogd.conf”
$klogParseKernelTimestamp on 
$klogKeepKernelTimestamp off 

这将删除内核时间戳ap像每一个内核消息的开头梨“[6448.546951]”在以下日志

Mar 31 14:36:14 localhost kernel: [ 6448.546951] iptables: IN=ppp0 OUT= MAC= SRC= 
0

我使用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 

我试图禁用TIMESTAMP WITH:

$klogParseKernelTimestamp on 
$klogKeepKernelTimestamp off 

但显示:

08月12日11时五十分22秒节点2 rsyslo gd-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 

谢谢前进。