iptables是一個強大的Linux防火牆,使用頻率極高。本文介紹如何查看iptables規則設置。.net
service iptables status --查看防火牆狀態orm
一、iptables -Lip
查看filter表的iptables規則,包括全部的鏈。filter表包含INPUT、OUTPUT、FORWARD三個規則鏈。
說明:-L是--list的簡寫,做用是列出規則。ci
二、iptables -L [-t 表名]get
只查看某個表的中的規則。
說明:表名一個有三個:filter,nat,mangle,若是沒有指定表名,則默認查看filter表的規則列表(就至關於第一條命令)。io
舉例:iptables -L -t filtertable
三、iptables -L [-t 表名] [鏈名]form
這裏多了個鏈名,就是規則鏈的名稱。
說明:iptables一共有INPUT、OUTPUT、FORWARD、PREROUTING、POSTROUTING五個規則鏈。
舉例:iptables -L INPUT
注意:鏈名必須大寫。在Linux系統上,命令的大小寫很敏感。class
四、iptables -n -Ltest
說明:以數字形式顯示規則。若是沒有-n,規則中可能會出現anywhere,有了-n,它會變成0.0.0.0/0
五、iptables -nv -L
說明:你也能夠使用「iptables -L -nv」來查看,這個列表看起來更詳細,對技術人員更友好,呵呵。
若是想刪除iptables規則咱們能夠以下操做
刪除用-D參數
刪除以前添加的規則(iptables -A INPUT -s 192.168.1.5 -j DROP):
[root@test ~]# iptables -D INPUT -s 192.168.1.5 -j DROP有時候要刪除的規則太長,刪除時要寫一大串,既浪費時間又容易寫錯,這時咱們能夠先使用–line-number找出該條規則的行號,再經過行號刪除規則。
[root@test ~]# iptables -nv --line-number
iptables v1.4.7: no command specified
Try `iptables -h' or 'iptables --help' for more information.
[root@test ~]# iptables -nL --line-number
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 DROP all -- 192.168.1.1 0.0.0.0/0
2 DROP all -- 192.168.1.2 0.0.0.0/0
3 DROP all -- 192.168.1.3 0.0.0.0/0
刪除第二行規則
[root@test ~]# iptables -D INPUT 2