4

I have IPTables rules set on a Linux device. I have a particular rule to drop the packets, and I wish to log the packets only if they're dropped by that specific rule, and not by the other rules.

Hence not written out to the syslog.

6

You could use rsyslog and set a custom --log-prefix on this specific rule when you're setting it up. This would allow you to setup a rsyslog rule to route any messages with this custom prefix to a individual log file.

This tutorial titled: Change the IPTables log file, shows the exact methodology. In general you'll setup your iptables rule like so:

$ sudo iptables -A INPUT -p tcp --dport 22 --syn -j LOG --log-prefix "iptables: "

And then create a corresponding rsyslog rule to log messages with this prefix:

# /etc/rsyslog.d/10-iptables.conf
:msg, contains, "iptables: " -/var/log/iptables.log
& ~

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.