Linux防火牆配置—允許轉寄

來源:互聯網
上載者:User

標籤:.com   add   pre   eth0   inpu   blank   service   防火牆   img   

一、實驗目標

  在上一次“Linux基礎網路搭建實驗”中,內、外網虛擬機器之所以能Ping通,是因為暫時關閉了防火牆,然而現實中這樣操作顯然存在很大的安全隱患,所以本次實驗在上次實驗的基礎下,開啟防火牆,並配置防火牆規則,使得內、外網虛擬機器任然能夠Ping通。

  (Linux基礎網路搭建實驗:http://www.cnblogs.com/liaoyuanyang/p/6749416.html)

  網路拓撲圖:

 二、實驗步驟

1、搭建的網路(參考“Linux基礎網路搭建實驗”)

2、在網關上開啟防火牆,此時內網虛擬機器不能Ping通外網虛擬機器

[[email protected] 案頭]# service iptables start

 

3、清除防火牆(Filter)所有規則

 一般來說,在重新制定防火牆規則的時候,應先將原先規則清楚,然後再一條一條來設定

[[email protected] 案頭]# iptables -F  //刪除所有已定的規則[[email protected] 案頭]# iptables -X  //殺掉多有使用者”自訂“的chain(或者說tables)
[[email protected] 案頭]# iptables -Z  //將所有的chain的計數與流量統計都歸零

 

4、定義預設規則

[[email protected] 案頭]# iptables -P INPUT DROP  //-P:定義策略(Policy)[[email protected] 案頭]# iptables -P OUTPUT DROP[[email protected] 案頭]# iptables -P FORWARD DROP[[email protected] 案頭]# iptables -A FORWARD -i eth0 -p icmp -j ACCEPT[[email protected] 案頭]# iptables -A FORWARD -i eth1 -p icmp -j ACCEPT
[[email protected] 案頭]# iptables-save  //列出完整的防火牆規則
規則解釋:
iptables -A FORWARD -i eth0 -p icmp -j ACCEPT
新增一條轉寄規則,允許從eth0進來的Ping包通過
-A:add,表示新增一條規則,位置在原本規則的最後面
-i:input,從哪個介面進,需要與INPUT鏈配合
-p:設定此規則適用於哪種資料包格式(如:tcp、udp、icmp和all)
icmp:Ping包
-j:後面接動作,主要的動作有:接受(ACCEPT)、丟棄(DROP)、拒絕(REJECT)及記錄(LOG)

三、測試結果

在內網虛擬機器上Ping外網虛擬機器

 

Linux防火牆配置—允許轉寄

聯繫我們

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