2.0-iptables詳解

來源:互聯網
上載者:User

標籤:2.0-iptables詳解

iptables    串連netfilter的工具


3張表  

filter    過濾進出資料包   預設3個鏈input output forward

nat       網路位址轉譯     預設3個鏈prerouting postrouting output

mangle    給資料做標記,根據標記繼續操作 預設5個鏈input output forward prerouting postrouting

常用的表和鏈有filter的input和output


iptables -nvL              查看filter表的規則,不指定-t預設為filter

iptables -t nat -nvL       查看nat表的規則

iptables -t mangle -nvL    查看mangle表的規則


iptables -Z                規則匹配計數器清零

iptables -F                清空filter表規則

service iptables save      儲存iptables規則到設定檔/etc/sysconfig/iptables

iptables-save > 1.txt      規則另存到指定的檔案

iptables-restore < 1.txt   通過備份檔案,恢複規則


iptables -t filter -I INPUT -p tcp --dport 80 -s 1.1.1.1 -j DROP

-I插入規則到指定序號,不指定,預設最開始    

                      iptables -t filter -I INPUT 3 -p tcp --dport 80 -s 1.1.1.1 -j DROP

-A插入規則到最末尾    iptables -t filter -A INPUT -p tcp --dport 80 -s 1.1.1.1 -j DROP

-D刪除指定的規則      iptables -t filter -D INPUT -p tcp --dport 80 -s 1.1.1.1 -j DROP

-j有3種動作:DROP直接丟棄    REJECT檢查後拒絕       ACCEPT接受


注意:如果針對連接埠操作,必須指定協議類型tcp/udp,否則報錯。


iptables -I INPUT -p tcp -s 1.1.1.1 -j ACCEPT   不指定連接埠,預設為所有連接埠。



iptables -P INPUT DROP     設定filter表INPUT鏈的預設策略為拒絕(總開關)


如果iptables規則太多,可用規則序號來刪除:

iptables -nvL --line-number           顯示filter表的規則序號

iptables -D INPUT 3                   刪除filter表中序號是3的規則


2.0-iptables詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.