分享

通过 modprobe 彻底禁用 netfilter | Jasey Wang

 昵称28748685 2016-01-03

要禁用 iptables 很简单,曲线救国,禁用掉模块就好了:
$ cat /etc/modprobe.d/blacklist-iptables.conf
alias ip_tables off

alias iptable off
alias iptable_nat off
alias iptable_filter off

alias nf_nat off
alias nf_conntrack_ipv4 off
alias nf_conntrack off
alias nf_defrag_ipv4 off

alias x_tables off

alias xt_limit off
alias xt_tcpudp off
alias xt_multiport off

alias ipt_REJECT off
alias ipt_LOG off

再启用上面的文件之前,记得先把 iptables 规则清空、rmmod 掉对应的模块。这也是另外一种防止 『dropping packet』 的方式。
netfilter 的模块在 /lib/modules/2.6.32-38-server/kernel/net/ipv4/netfilter/ 里面。

通过 systool 可以看到被加载模块的 section:
# systool  -v -m ip_tables
Module = "ip_tables"

  Attributes:
    initstate           = "live"
    refcnt              = "1"
    srcversion          = "DC18D42211BCD06DB350605"

  Sections:
    .bss                = "0xffffffffa0032d60"
    .data               = "0xffffffffa00328e0"
    .data.read_mostly   = "0xffffffffa0032980"
    .exit.text          = "0xffffffffa00324fc"
    .gnu.linkonce.this_module= "0xffffffffa0032b00"
    .init.text          = "0xffffffffa000c000"
    .note.gnu.build-id  = "0xffffffffa0032568"
    .parainstructions   = "0xffffffffa0032650"
    .ref.text           = "0xffffffffa0032550"
    .rodata             = "0xffffffffa00325a0"
    .rodata.str1.1      = "0xffffffffa00325c8"
    .rodata.str1.8      = "0xffffffffa0032680"
    .strtab             = "0xffffffffa000cf78"
    .symtab             = "0xffffffffa000c0c0"
    .text               = "0xffffffffa002f000"
    __kcrctab           = "0xffffffffa0032770"
    __ksymtab           = "0xffffffffa0032740"
    __ksymtab_strings   = "0xffffffffa0032788"
    __mcount_loc        = "0xffffffffa00327c0"

 
查看当前模块的所有的详细情况:
$ modprobe -c | less

module 也有  Alias 一说,因此 "alias my-mod really_long_modulename" 意味着你可以使用 "modprobe my-mod" 而非 "modprobe really_long_modulename" 来加载模块。所以上面的 off 就好理解了。

跟 module 相关的还有个 blacklist 概念:
$ cat /etc/modprobe.d/blacklist-iptables.conf
blacklist ip_tables

blacklist iptable
blacklist iptable_nat
blacklist iptable_filter

blacklist nf_nat
blacklist nf_conntrack_ipv4
blacklist nf_conntrack
blacklist nf_defrag_ipv4

blacklist x_tables

blacklist xt_limit
blacklist xt_tcpudp
blacklist xt_multiport

blacklist ipt_REJECT
blacklist ipt_LOG

这个可以在系统启动的时候禁止加载这个模块,但是,尽管启动的时候禁掉了,但是如果在进入系统之后执行:
# iptables -L -n

系统又会自动加载诸如:
iptable_filter          1841  0
ip_tables              18201  1 iptable_filter
x_tables               22361  1 ip_tables
等模块,因此这种方式并不是很好。顺便提一句,使用 "blacklist" 可能会遇到依赖的问题,因此使用下面这个方式会比上面的这个更好:
install MODULE_NAME /bin/false

ref:
https://wiki./index.php/Kernel_modules

      本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
      转藏 分享 献花(0

      0条评论

      发表

      请遵守用户 评论公约

      类似文章 更多