linux系統中查看己設定iptables規則__linux

來源:互聯網
上載者:User

  有時我們剛接手伺服器以前網管做的iptables規則我們可能不知道,需要查看一下iptables規則怎麼寫以來瞭解機器了,下面我來介紹查看iptables規則執行個體。

iptables是一個強大的Linux防火牆,使用頻率極高。本文介紹如何查看iptables規則設定。

1、iptables -L

查看filter表的iptables規則,包括所有的鏈。filter表包含INPUT、OUTPUT、FORWARD三個規則鏈。
說明:-L是--list的簡寫,作用是列出規則。

2、iptables -L [-t 表名]

只查看某個表的中的規則。
說明:表名一個有三個:filter,nat,mangle,如果沒有指定表名,則預設查看filter表的規則列表(就相當於第一條命令)。

舉例:iptables -L -t filter

3、iptables -L [-t 表名] [鏈名]

這裡多了個鏈名,就是規則鏈的名稱。
說明:iptables一共有INPUT、OUTPUT、FORWARD、PREROUTING、POSTROUTING五個規則鏈。
舉例:iptables -L INPUT
注意:鏈名必須大寫。在Linux系統上,命令的大小寫很敏感。

4、iptables -n -L

說明:以數字形式顯示規則。如果沒有-n,規則中可能會出現anywhere,有了-n,它會變成0.0.0.0/0

5、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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.