【解决】CentOS防火墙无法启动的问题

[Author]: kwu

CentOS防火墙无法启动,在线服务器都需要开启防火墙服务,这是linux系统安全防护最直接有效方式。

1、如果出现 

service iptables start 

service iptables restart

无法启动/重启防火墙时。


2、最佳的方法是修改配置文件

vi /etc/sysconfig/iptables

[plain]  view plain copy
  1. # Firewall configuration written by system-config-firewall  
  2. # Manual customization of this file is not recommended.  
  3. *filter  
  4. :INPUT ACCEPT [0:0]  
  5. :FORWARD ACCEPT [0:0]  
  6. :OUTPUT ACCEPT [0:0]  
  7. -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
  8. -A INPUT -p icmp -j ACCEPT  
  9. -A INPUT -i lo -j ACCEPT  
  10. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT  
  11. -A INPUT -j REJECT --reject-with icmp-host-prohibited  
  12. -A FORWARD -j REJECT --reject-with icmp-host-prohibited  
  13. COMMIT  


然后再启动防火墙

service iptables start 

查看防火墙服务

service iptables status



3、如果需要开启例外端口则,增加如下配置:

vi /etc/sysconfig/iptables 

[plain]  view plain copy
  1. # Firewall configuration written by system-config-firewall  
  2. # Manual customization of this file is not recommended.  
  3. *filter  
  4. :INPUT ACCEPT [0:0]  
  5. :FORWARD ACCEPT [0:0]  
  6. :OUTPUT ACCEPT [0:0]  
  7. -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
  8. -A INPUT -p icmp -j ACCEPT  
  9. -A INPUT -i lo -j ACCEPT  
  10. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT  
  11. -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT  
  12. -A INPUT -j REJECT --reject-with icmp-host-prohibited  
  13. -A FORWARD -j REJECT --reject-with icmp-host-prohibited  
  14. COMMIT  

如上,增加了3306服务端口



如果需要关闭防火墙自动启动则

查看状态

chkconfig --list iptables

关闭自动启动
chkconfig iptables off

查看状态

chkconfig --list iptables
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值