Sunday, February 27, 2022

[SOLVED] rsyslog - Property-based filtering not working

Issue

I almost hate to submit a topic for this, but I haven't been able to figure it out on my own. I'm running a Federoa 17 server, and I'm attempting to log dropped packets from iptables to a separate log file via rsyslog, but it keeps sending them to /var/log/messages instead.

Snippet from my firewall script:

#!/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

The config file that SHOULD be catching the messages from iptables:

[root@fc17 ]# cat /etc/rsyslog.d/iptables.conf 
:msg, startswith, "iptables: "  /var/log/iptables.log
& ~

Snippet from my rsyslog.conf file:

#### 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

I've restarted both iptables and rsyslog multiple times since making the changes, and no matter what, it will only only log dropped packets from iptables to /var/log/messages.

I heard running rsyslog in compatibility mode can cause various problems. Could this be the case here? Here are its run-options on my system:

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

Solution

startswith comparison operator didn't work,because msg didn't begin with iptables: when i checked my logs.

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

but contains comparison operator worked on my FC18

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

Ref: Rsyslog site



Answered By - clement
Answer Checked By - Marie Seifert (WPSolving Admin)