linux iptables 规则的删除

原文:http://www.weiruoyu.cn/?p=392 ios


会添加防火墙规则,可是不会删除,在晚上找了一篇文章,感受很好,转载过来tcp

http://jar-c.blog.163.com/blog/static/116401250201061541150973/ide

方法二很是管用,spa

在学IPTABLES 时,看书上只有往链里添加规则,并无删除规则,而在实际的使用时。删除规则也很经常使用啊。blog

在网上找了一下,删除规则的方法:ip

语法是: iptables -D chain rulenum [options]get

其中: chain 是链的意思,就是INPUT FORWARD 之类的it

rulenum 是规则的编号。从1 开始。能够使用 --line-numbers 列出规则的编号io


因此,例如上面要删除一个INPUT链的规则的话能够这样:iptables -D INPUT 3table

意思是删除第3条规则。

还有第二种方法。第二种办法是 -A 命令的映射,不过用-D替换-A。当你的链中规则很复杂,而你不想计算它们的编号的时候这就十分有用了。也就是说,你如何用iptables -A.... 语句定义了一个规则,则删除此规则时就用 -D 来代替- A 其他的都不变便可。

======================

说一下上面的 --line-numbers 选项,以下面的命令:

#iptables -L INPUT --line-numbers 列出INPUT 链全部的规则

num target prot opt source destination
1 REJECT tcp -- anywhere anywhere tcp dpt:microsoft-ds reject-with icmp-port-unreachable
2 REJECT tcp -- anywhere anywhere tcp dpt:135 reject-with icmp-port-unreachable
3 REJECT tcp -- anywhere anywhere tcp dpt:netbios-ssn reject-with icmp-port-unreachable
4 REJECT udp -- anywhere anywhere udp dpt:microsoft-ds reject-with icmp-port-unreachable
5 REJECT udp -- anywhere anywhere udp dpt:135 reject-with icmp-port-unreachable
...
...
删除指定行规则:
[root@localhost rc.d]#
iptables -D INPUT 4

参考:http://www.weiruoyu.cn/?p=392

相关文章
相关标签/搜索