代码之家  ›  专栏  ›  技术社区  ›  Emre Yazici

加载的iptables模块列表

  •  14
  • Emre Yazici  · 技术社区  · 15 年前

    有什么方便的方法来展示上膛的吗 伊普斯特 模块列表?我可以通过列出/lib/iptables/(或/lib64/iptables/)目录来显示已安装的模块,但我需要活动模块列表。

    6 回复  |  直到 6 年前
        1
  •  22
  •   Emre Yazici    15 年前

    加载 伊普斯特 模块可在 /proc/net/ip_表匹配 proc文件系统项。

    cat /proc/net/ip_tables_matches
    

    在PHP中,我可以访问加载的 伊普斯特 通过加载和分解文件内容的模块:

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

    当然,它需要挂载proc文件系统(大多数gnu linux发行版默认挂载它)

        2
  •  4
  •   Nikhil Freddroid    12 年前

    这是一个非常古老的帖子,但我们来看看:

    # lsmod | grep ip
    

    显示加载模块的列表,我认为这些模块大部分与iptables相关… /proc/net/ip_tables_matches 不显示模块(至少不在RHEL 6中)

        3
  •  2
  •   Sean Mickey    9 年前

    查看以下目录(根据内核版本替换):

    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"
    

    这似乎没有很好的记录。

        4
  •  1
  •   sjas Pushkar Phule    9 年前

    请尝试此方法快速浏览系统上的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#
    
        5
  •  0
  •   Aas    10 年前

    正如Gonio所建议的,lsmod列出了所有加载的内核模块,但是grepping“ip”不会给您所有的iptables模块。

    我宁愿用

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

    不过,我不确定清单是否完整。

        6
  •  0
  •   Keith Macdonald    6 年前

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

    首先确保您拥有IPTC库。 sudo-pip安装--升级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("------------------------------------------")