歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下簡單防火牆的設置

Linux下簡單防火牆的設置

日期:2017/2/28 15:33:40   编辑:Linux教程

對於個人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”。

Copyright © Linux教程網 All Rights Reserved