Linux下簡單防火牆的設定

來源:互聯網
上載者:User

對於個人VPS來說,簡單的防火牆設定也是有必要的,具體方法如下:

1. 先檢查一下防火牆的功能是否開啟:
# /etc/init.d/iptables status

2. 設定輸入、輸出和轉寄三個鏈的預設政策:
# iptables -P INPUT ACCEPT
# iptables -P OUTPUT ACCEPT
# iptables -P FORWARD ACCEPT

3. 清空全部預設的防火牆:
# iptables -F
# iptables -X
# iptables -Z

4. 設定loopback介面不受然後限制:
# iptables -A INPUT -i lo -j ACCEPT

5. 設定開放所有由本機發出去的請求的響應包
# iptables -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT

6. 設定放開本機提供的www服務:
# iptables -A INPUT -p TCP –dport 80 -j ACCEPT

7. 設定放開本機提供的ssh服務:
# iptables -A INPUT -p TCP –dport 22 -j ACCEPT

8. 設定輸入鏈的預設政策為DROP:
# iptables -P INPUT DROP

9. 儲存這些路由資訊:
# /etc/init.d/iptables save

註:
需要先設定輸入鏈的預設政策為ACCEPT, 給自己留一條後路,免得ssh串連被防火牆block,那樣的話,就只能想辦法重啟伺服器,或者跑到伺服器上tty登入了。所以,還是先把INPUT政策置為ACCEPT,再進行防火牆的操作,最後再執行”iptables -P INPUT DROP”。

 
相關文章

聯繫我們

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