Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  85] [ 0]  / answers: 1 / hits: 334636  / 2 Years ago, sat, august 20, 2022, 12:38:58

I have this rule in my iptables:



iptables -A INPUT -s 192.168.11.0/24 -j LOG


My question is:



Where is the iptables log file, and how can I change that?


More From » log

 Answers
2

These logs are generated by the kernel, so they go to the file that receives kernel logs: /var/log/kern.log.


If you want to redirect these logs to a different file, that can't be done through iptables. It can be done in the configuration of the program that dispatches logs: rsyslog. In the iptables rule, add a prefix that isn't used by any other kernel log:


iptables -A INPUT -s 192.168.11.0/24 -j LOG --log-prefix='[netfilter] '

Following the example set by 20-ufw.conf, create a file under /etc/rsyslog.d/00-my_iptables.conf containing:


:msg,contains,"[netfilter] " -/var/log/iptables.log
& stop

Putting the rule early (the file names in /etc/rsyslog.d are used in lexicographic order) and adding &stop causes these logs to go only to the specified location and not to the default location as well.


Rsyslog has to be restarted for the config changes to take place.


[#29332] Saturday, August 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
measord

Total Points: 259
Total Questions: 131
Total Answers: 106

Location: Venezuela
Member since Sun, Oct 2, 2022
2 Years ago
;