> RedHat >

用命令行方式关闭linux防火墙

#/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防火墙的设置修改。

(责任编辑:IT)