一、在linux系統裏面找到並打開編輯配置防火牆的文件,執行命令:
vi /etc/sysconfig/iptables。linux
二、在上面打開的文件裏面加入一下語句:
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(容許80端口經過防火牆,這裏以80端口爲例)。tcp
須要注意的是上面這條語句不要加載文件的最後面,這樣會致使防火牆啓動失敗,正確的應該是添加到默認的22端口這條規則的下面this
三、添加好以後防火牆規則以下所示:
spa
# Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
或者 /etc/init.d/iptables restartservice iptables restart
重啓以下:
[root@localhost bin]# /etc/init.d/iptables restart
iptables:將鏈設置爲政策 ACCEPT:filter [肯定]
iptables:清除防火牆規則: [肯定]
iptables:正在卸載模塊: [肯定]
iptables:應用防火牆規則: [肯定]
查看防火牆規則是否生效rest
[root@localhost bin]# iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) target prot opt source destination REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) target prot opt source destination