歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Ubuntu 14.04 配置iptables防火牆

Ubuntu 14.04 配置iptables防火牆

日期:2017/2/28 13:39:48   编辑:Linux教程

Ubuntu默認安裝是沒有開啟任何防火牆的,為了服務器的安全,建議大家安裝啟用防火牆設置,這裡推薦使用iptables防火牆.如果mysql啟本地使用,可以不用打開3306端口.

# whereis iptables #查看系統是否安裝防火牆可以看到:
iptables: /sbin/iptables /usr/share/iptables /usr/share/man/man8/iptables.8.gz #表示已經安裝iptables
apt-get install iptables #如果默認沒有安裝,請運行此命令安裝防火牆

# iptables -L #查看防火牆配置信息,顯示如下:
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination

# vi /etc/iptables.rules

添加以下內容(備注:80是指web服務器端口,3306是指MySQL數據庫鏈接端口,22是指SSH遠程管理端口.)
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:syn-flood - [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p icmp -m limit --limit 100/sec --limit-burst 100 -j ACCEPT
-A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
-A INPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j syn-flood
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN
-A syn-flood -j REJECT --reject-with icmp-port-unreachable
COMMIT

# iptables-restore < /etc/iptables.rules #使防火牆規則生效

# vi /etc/network/if-pre-up.d/iptables #創建文件,添加以下內容,使防火牆開機啟動
#!/bin/bash
iptables-restore < /etc/iptables.rules

# chmod +x /etc/network/if-pre-up.d/iptables #添加執行權限

# iptables -L -n查看規則是否生效.

Copyright © Linux教程網 All Rights Reserved