
Ich möchte meine von iptables generierten Protokollmeldungen über rsyslogd in einer anderen Datei speichern.
Derzeit verwende ich diesen Code von /etc/rsyslog.d/20-custom.conf
:
# Log cron to cron.log and not to syslog
*.*;cron,auth,authpriv.none -/var/log/syslog
cron.* /var/log/cron.log
# Log firewall to extra log
:msg,contains,"[BLOCK " /var/log/firewall.log
& stop
Meine Cron-Protokolle sind in Ordnung, sie werden nur in protokolliert cron.log
, aber meine iptables-Protokolle werden sowohl in als syslog
auch in protokolliert firewall.log
. Gibt es eine Möglichkeit, sie nur in zu protokollieren firewall.log
?
Meine Systemdaten:
> rsyslogd -v
rsyslogd 8.16.0, compiled with:
PLATFORM: x86_64-pc-linux-gnu
PLATFORM (lsb_release -d):
FEATURE_REGEXP: Yes
GSSAPI Kerberos 5 support: Yes
FEATURE_DEBUG (debug build, slow code): No
32bit Atomic operations supported: Yes
64bit Atomic operations supported: Yes
memory allocator: system default
Runtime Instrumentation (slow code): No
uuid support: Yes
Number of Bits in RainerScript integers: 64
Linux MYHOSTNAME 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
Antwort1
Sie müssen den Firewall-Logging-Teil vor andere Regeln verschieben, so dass es aussieht wie
# Log firewall to extra log
:msg,contains,"[BLOCK " /var/log/firewall.log
& stop
# Log cron to cron.log and not to syslog
*.*;cron,auth,authpriv.none -/var/log/syslog
cron.* /var/log/cron.log
Die Regeln werden in der Reihenfolge berücksichtigt, so dass Sie es jetzt eine Nachricht passend haben*.*;cron,auth,authpriv.keinewird immer ins Syslog geschrieben, auch wenn es auch übereinstimmt:msg,enthält,"[BLOCK "und wird in die Datei firewall.log geschrieben. Der Stoppbefehl steht in der Datei einfach zu spät, um irgendetwas zu stoppen.
Siehe auchhttps://www.rsyslog.com/writing-specific-messages-to-a-file-and-discarding-them/