谁能帮我找出这里发生了什么?我有一些设置跟踪数据包计数的规则。当我以 root 身份运行以下脚本时:
#!/bin/bash
iptables -t mangle -xnvL
Run Code Online (Sandbox Code Playgroud)
我得到我期望的输出:
//snip
233203 199929802 MARK //blah blah blah
//snip
Run Code Online (Sandbox Code Playgroud)
但是,我想将它作为 cacti 的一部分运行,它作为 apache 运行。现在apache不能运行iptables,这就是我有脚本的原因。我将其设置为 SUID 根:
-rwsr-sr-x 1 root root 37 May 14 23:06 iptables_packet_report.sh
Run Code Online (Sandbox Code Playgroud)
但是后来我得到了这个输出:
server # sudo -u apache ./iptables_packet_report.sh
iptables v1.4.2: can't initialize iptables table `mangle': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
Run Code Online (Sandbox Code Playgroud)
显然我的内核很好,而且我以非 root 用户身份运行它的事实搞砸了一些事情,但我不明白为什么。我确实用 [演示]( http://en.wikipedia.org/wiki/Setuid#Demonstration )仔细检查了 SUID并确认它正在工作。
server # sudo -u apache …
Run Code Online (Sandbox Code Playgroud)