是否有任何方便的方式来显示加载的iptables模块列表?我可以通过列出/ lib/iptables /(或/ lib64/iptables /)目录来显示已安装的模块,但我需要活动模块列表.
Emr*_*ici 22
可以在/ proc/net/ip_tables_matches proc filesystem条目中找到已加载的iptables模块.
cat /proc/net/ip_tables_matches
Run Code Online (Sandbox Code Playgroud)
在PHP中,我可以通过加载和爆炸文件内容来访问加载的iptables模块:
$content = file_get_contents('/proc/net/ip_tables_matches');
$modules = explode("\n", $content);
Run Code Online (Sandbox Code Playgroud)
当然它需要安装proc文件系统(大多数GNU Linux发行版默认安装它)
小智 6
查看以下目录(根据您的内核版本进行替换):
ls /lib/modules/2.6.32-504.8.1.el6.x86_64/kernel/net/netfilter/
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方式加载模块(删除.ko
目录中列出的内容):
modprobe nf_conntrack_ftp
Run Code Online (Sandbox Code Playgroud)
或者,您可以通过将其添加到以下位置来确保它在启动时加载:
/etc/sysconfig/iptables-config (RHEL/CENTOS)
IPTABLES_MODULES="nf_conntrack_ftp"
Run Code Online (Sandbox Code Playgroud)
这似乎没有很好的记录。
小智 5
这是一个非常古老的帖子,但我们继续:
# lsmod | grep ip
Run Code Online (Sandbox Code Playgroud)
显示已加载模块的列表,我认为大多数与 iptables 相关...
/proc/net/ip_tables_matches
不显示模块(至少在 RHEL 6 中没有)
尝试此操作以快速了解系统上存在的 netfilter 模块,这里是用于粘贴的一行:
for i in /lib/modules/$(uname -r)/kernel/net/netfilter/*; do echo -e "\e[33;1m$(basename "$i")\e[0m"; strings "$i" | \grep -e description -e depends| sed -e 's/Xtables: //g' -e 's/=/: /g' -e 's/depends=/depends on: /g'; echo; done
Run Code Online (Sandbox Code Playgroud)
再次为了可读性,添加了换行符:
#!/bin/bash
for i in /lib/modules/$(uname -r)/kernel/net/netfilter/*
do
echo -e "\e[33;1m$(basename "$i")\e[0m"
strings "$i" | \grep -e description -e depends | sed -e 's/Xtables: //g' -e 's/=/: /g' -e 's/depends=/depends on: /g'
echo
done
Run Code Online (Sandbox Code Playgroud)
文件名将显示为黄色,从中您可以猜测有问题的模块是否存在。描述和依赖项是下面接下来的两行。
这不会涵盖所有内容(因为这太容易了,ofc)。仅手动查找模块,看看它们是否存在,即可为您提供 100% 准确的信息。
iptables -m <match/module name> --help
Run Code Online (Sandbox Code Playgroud)
如果您的系统上存在模块,则在帮助文本的末尾,您将获得一些有关如何使用它的信息:
ctr-014# iptables -m limit --help
iptables v1.4.14
Usage: iptables -[ACD] chain rule-specification [options]
iptables -I chain [rulenum] rule-specification [options]
...
[!] --version -V print package version.
limit match options:
--limit avg max average match rate: default 3/hour
[Packets per second unless followed by
/sec /minute /hour /day postfixes]
--limit-burst number number to match in a burst, default 5
ctr-014#
Run Code Online (Sandbox Code Playgroud)
如果您的系统上不存在该模块:
ctr-014# iptables -m iplimit --help
iptables v1.4.14: Couldn't load match `iplimit':No such file or directory
Try `iptables -h' or 'iptables --help' for more information.
ctr-014#
Run Code Online (Sandbox Code Playgroud)