I’ve been trying to log iptables to a file. from my understanding its suppose to log to kern.log or messages but that doesn’t seem to be happening. when using the Digital Ocean console when inputting ‘iptables -A INPUT -j LOG’ it’ll start logging the NIC but outputs it to the console not to kern.log or messages. even adding 'kern.warning /var/log/iptables.log’ to rsyslog yields the same results. What am I doing wrong or how can I monitor traffic and log to file as this is how I was monitoring traffic and rejecting IPs via fail2ban and log files with regular expressions but that doesn’t seem to work anymore. any help would be appreciated. Thanks.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @ace31585,

Usually you should be able to see all messages in your journal:


Having said that, as far as I know this is not something that can be reviewed anytime except real time.

As mentioned you’ve added kern.warning /var/log/iptables.log to rsyslog. Can you by any chance try and add it at /etc/syslog.conf and see if that would work for you?

Additionally, most probably you’ve tried this but can you give the bellow a try

iptables -N LOGGING
iptables -A OUTPUT -j LOGGING
iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables-Rules  Dropped: " --log-level 4
iptables -A LOGGING -j DROP

This will output messages to /var/log/messages (unless you’ve specified it somewhere else from your syslog conf) with the prefix “IPTables-Rules Dropped: ”