iptables logging

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.

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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: "