ber*_*nie 12 linux debian iptables log-files logging
我正在尝试使用 IPtables 的 TRACE 目标,但似乎无法记录任何跟踪信息。我想使用这里描述的内容: Debugger for Iptables。
来自 iptables man for TRACE:
Run Code Online (Sandbox Code Playgroud)This target marks packes so that the kernel will log every rule which match the packets as those traverse the tables, chains, rules. (The ipt_LOG or ip6t_LOG module is required for the logging.) The packets are logged with the string prefix: "TRACE: tablename:chain- name:type:rulenum " where type can be "rule" for plain rule, "return" for implicit rule at the end of a user defined chain and "policy" for the policy of the built in chains. It can only be used in the raw table.
我使用以下规则:iptables -A PREROUTING -t raw -p tcp -j TRACE
但在 /var/log/syslog 或 /var/log/kern.log 中没有附加任何内容!
是不是还少了一步?我找错地方了吗?
即使我找不到日志条目,由于数据包计数器增加,TRACE 目标似乎设置正确:
# iptables -L -v -t raw
Chain PREROUTING (policy ACCEPT 193 packets, 63701 bytes)
pkts bytes target prot opt in out source destination
193 63701 TRACE tcp -- any any anywhere anywhere
Chain OUTPUT (policy ACCEPT 178 packets, 65277 bytes)
pkts bytes target prot opt in out source destination
Run Code Online (Sandbox Code Playgroud)
该规则iptables -A PREROUTING -t raw -p tcp -j LOG
确实将数据包信息打印到 /var/log/syslog... 为什么 TRACE 不起作用?
ako*_*nov 16
似乎(即对我有用)需要新内核(对于 IPv4):
modprobe nf_log_ipv4
sysctl net.netfilter.nf_log.2=nf_log_ipv4
Run Code Online (Sandbox Code Playgroud)
学分:
我发现我需要按以下顺序执行前面的两个答案:
sudo modprobe ipt_LOG
sudo sysctl net.netfilter.nf_log.2=ipt_LOG
Run Code Online (Sandbox Code Playgroud)
以下是我在此过程中发现的一些事情。
您可以通过以下方式获取有效记录器的列表(以及当前选择的记录器):
cat /proc/net/netfilter/nf_log
Run Code Online (Sandbox Code Playgroud)
此处的数字代表协议族编号,如 中所定义/usr/include/bits/socket.h
。2 是AF_INET
(即 IPv4),10 是AF_INET6
(IPv6)。
小智 7
这个问题专门询问 debian squeeze,所以这个答案并不严格相关,但由于这是“iptables TRACE”的最高结果,我想澄清一下。
这些答案都是正确的,但对于现代系统,很可能您实际上正在使用 iptables-nft,请检查iptables -V
,简单地说您的用户空间程序的行为非常像真正的 iptables,但在幕后它是内核中的 nftables,在这种情况下 ipt_LOG 和其他答案中提到的内容(以及我发现的关于该主题的两个教程)将不起作用,相反,您可以使用用户空间程序检查跟踪日志xtables-monitor --trace
,来源:
https ://ipset.netfilter.org/iptables-extensions.man.html #lbDX
进一步阅读 redhat 有关 iptables-nft 的内容: https://developers.redhat.com/blog/2020/08/18/iptables-the-two-variants-and-their-relationship-with-nftables