使用一下命令:
#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
#/etc/rc.d/init.d/iptables save
重啟計算機後,防火牆默認已經開放了80和22兩個端口。
臨時性的完全關閉防火牆,可以不重啟機器:
#/etc/init.d/iptables status ##查看防火牆狀態
#/etc/init.d/iptable stop ##本次關閉防火牆
#/etc/init.d/iptable restart ##重啟防火牆
永久性關閉防火牆:
#chkconfig --level 35 iptables off (注意中間的是兩個英式小短線;重啟)
附:
設置防火牆開放端口的方法如下:
vi /etc/sysconfig/iptables
修改防火牆時注意最好留下VNC和SSH的管理端口。
下面是一個iptables的示例:
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT
要根據自己需求情況來修改這個文件,舉例來說,如果你不希望開放80端口提供web服務,那麼應該相應的刪除這一行:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
全部修改完之後重啟iptables:
service iptables restart
你可以驗證一下是否規則都已經生效:iptables -L
這樣,我們就完成了CentOS防火牆的設置修改。