iptables規則的刪除-怎麼刪除一條已有的iptables規則

語法是: iptables -D chain rulenum [options]
其中: chain 是鏈的意思,就是INPUT FORWARD 之類的定語
rulenum 是該條規則的編號。從1開始。可使用iptables -L INPUT –line-numbers列出指定的鏈的規則的編號來。

因此,例如上面要刪除一個INPUT鏈的規則的話能夠這樣:ios

iptables -D INPUT 3

意思是刪除第3條規則。

還有第二種方法
第二種辦法是 -A 命令的映射,不過用-D替換-A。當你的鏈中規則很複雜,而你不想計算它們的編號的時候這就十分有用了。
也就是說,你如何一開始時用iptables -A…. 語句定義了一個規則,那麼刪除此條規則時直接用 -D 來代替- A, 其他的都不變便可,而不須要什麼編號了。

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

說一下上面的 –line-numbers 選項,以下面的命令:tcp

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
…
…

刪除指定的第4行規則:spa

iptables -D INPUT 4
[root@tp ~]# iptables -F 清除預設表filter中的全部規則鏈的規則
[root@tp ~]# iptables -X 清除預設表filter中使用者自定鏈中的規則
相關文章
相關標籤/搜索