I'm looking for an easy way to follow a packet through the iptables rules. This is not so much about logging, because I don't want to log all traffic (and I only want to have LOG targets for very few rules).
Something like Wireshark for Iptables. Or maybe even something similar to a debugger for a programming language.
Thanks Chris
Note: It doesn't have to be a fancy GUI tool. But it must do more than just showing a package counter or so.
Update: It almost looks as if we can't find anything that provides the functionality that is asked for. In that case: Let's at least find a good technique that's based on iptables logging - which can be easily turned on and off, and doesn't require to write iptables rules redundantly (having to write the same rule for -j LOG
and -j ...
)
If you have a recent enough kernel and version of iptables you can use the TRACE target (Seems to be builtin on at least Debian 5.0). You should set the conditions of your trace to be as specific as possible and disable any TRACE rules when you are not debugging because it does spew a lot of information to the logs.
If you added rules like this
You will be supplied with output that looks like this.
I can't think of a direct solution, but I can think of a round about way of tracking a packet.
Three answers on one post:
1) Debug by script:
2) Debug by syslog
From this website :http://www.brandonhutchinson.com/iptables_fw.html
3) No debug, nice iptables edit:
Also this can be helpfull: http://www.fwbuilder.org/
had the same question and found Zoredache pointing to TRACE / ipt_LOG was the solution!
Additionally I found a script which inserts/removes LOG-rules preceding all currently active iptables rules. I tried it out and found it to be a really nice tool. - Output is similar to the TRACE solution - Advantage: it works on the active iptables configuration, no matter where it was loaded from. You can turn logging on/off on the fly! You don't need to modify any firewall-scripts which might have been generated by Firewall Builder or tool whatever you use... - Disadvantage: without modification, the script creates LOG-rules for ALL active rules. Instead, when using TRACE rules, you'll probably restrict logging to addresses/services/connections for which you want to investigate iptables processing now.
Anyhow, I like the aproach :) Kudos to Tony Clayton, have a look: http://lists.netfilter.org/pipermail/netfilter/2003-March/043088.html
Regards, Chris
I usually use packets and bytes counters to see how rules work and to find what is missing or wrong.
You can view them by "iptables -nvL".
AFAIK an IP packet traverses the rule chain until the first match. So I don't really see what's the problem here. If you have:
And a packet makes it into the log, it means that rule 3 is the first matching rule.