加载的iptables模块列表

问题描述 投票:15回答:6

有没有显示加载的iptables模块列表中的任何方便的方法?我可以显示通过上市/ lib中/ iptables的/(或/ lib64目录/ iptables的/)目录中安装模块,但我需要的有源模块列表。

iptables
6个回答
22
投票

加载的iptables模块可以在/ proc /网/ ip_tables_matches proc文件系统条目中找到。

cat /proc/net/ip_tables_matches

在PHP中,我可以通过加载和爆炸文件内容访问加载的iptables模块:

$content = file_get_contents('/proc/net/ip_tables_matches');
$modules = explode("\n", $content);

当然,它需要被安装proc文件系统(大多数GNU Linux发行版默认安装它)


4
投票

这是一个非常老的文章,但在这里我们去:

# lsmod | grep ip

显示加载的模块,我认为大多数都涉及到iptables的名单... /proc/net/ip_tables_matches没有显示模块(至少在RHEL 6)


2
投票

您可以在以下目录中的样子(每内核版本替换):

ls /lib/modules/2.6.32-504.8.1.el6.x86_64/kernel/net/netfilter/

您可以使用(丢弃.ko在目录中列出)加载模块:

modprobe nf_conntrack_ftp

或者,你可以确保它是通过将其添加在开机加载:

/etc/sysconfig/iptables-config (RHEL/CENTOS) 

IPTABLES_MODULES="nf_conntrack_ftp"

这似乎是不良记录。


1
投票

试试这个对你的系统中,在这里一个班轮粘贴在netfilter的模块快速概述:

for i in /lib/modules/$(uname -r)/kernel/net/netfilter/*; do echo "\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

同样是为了便于阅读,添加了新行:

#!/bin/bash
for i in /lib/modules/$(uname -r)/kernel/net/netfilter/*
do 
    echo "\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

文件名会显示为黄色,从中如果有问题的模块不存在或不是你能猜到。描述和依赖性低于接下来的两行。

这不会面面俱到(因为这将是太容易了,OFC)。只有仰视模块手动,看看它们存在,给你100%的准确信息。

iptables -m <match/module name> --help

如果你的系统中存在一个模块,在帮助文档的最后,你会得到关于如何使用它的一些信息:

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# 

它的模块不存在你的系统上:

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#

0
投票

由于房角曾建议的lsmod列出所有加载的内核模块,但grepping“IP”是不会给你所有的iptables模块。

我宁愿用

lsmod|grep -E "nf_|xt_|ip"

静静的,我不知道该列表将完成。


0
投票

作为一种替代方法,这也可以用Python脚本来完成。

首先请确保您有IPTC库。须藤PIP安装--upgrade中的python-的iptables

(假设Python3是您的版本)

import iptc
table = iptc.Table(iptc.Table.FILTER)
for chain in table.chains:
    print("------------------------------------------")
    print("Chain ", chain.name)
    for rule in chain.rules:
        print("Rule ", "proto", rule.protocol, "src:", rule.src, "dst:" , rule.dst, "in:", rule.in_interface, "out:", rule.out_interface)
        print("Matches:")
        for match in rule.matches:
            print(match.name)
        print("Target:")
        print(rule.target.name)
print("------------------------------------------")
© www.soinside.com 2019 - 2024. All rights reserved.