linux下命令行方式关闭防火墙,即iptables防火墙,分两种情况。
在iptables防火墙中开启80(www)与22(ssh)端口: #/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两个端口。
1,永久性关闭防火墙,使用chkconfig命令: #chkconfig --level 35 iptables off (注意中间的是两个英式小短线;重启)
2,临时性的完全关闭防火墙,可以不重启机器: #/etc/init.d/iptables status ##查看防火墙状态 #/etc/init.d/iptables stop ##本次关闭防火墙 #/etc/init.d/iptables restart ##重启防火墙
这里分享下设置防火墙开放端口的方法:
一个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) |