linux – 为什么这个iptables文件行在CentOS 6中失败了

前端之家收集整理的这篇文章主要介绍了linux – 为什么这个iptables文件行在CentOS 6中失败了前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
您好,任何人都可以帮助我理解为什么第15行在我的iptables文件中失败了.我正在使用CentOS 6.

当我尝试重新启动iptables服务时,请获取以下内容

  1. [root@dbserver ~]# service iptables restart
  2. iptables: Flushing firewall rules: [ OK ]
  3. iptables: Setting chains to policy ACCEPT: filter [ OK ]
  4. iptables: Unloading modules: [ OK ]
  5. iptables: Applying firewall rules: iptables-restore: line 15 Failed
  6. [Failed]

我的iptables文件如下:

  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
  14. #-A RH-Firewall-1-INPUT -m tcp -p tcp --dport 80 -j ACCEPT
  15. -A RH-Firewall-1-INPUT -m tcp -p tcp --dport 53 -j ACCEPT
  16. -A RH-Firewall-1-INPUT -m udp -p tcp --dport 53 -j ACCEPT
  17. -A RH-Firewall-1-INPUT -m tcp -p tcp --dport 443 -j ACCEPT
  18. -A RH-Firewall-1-INPUT -m tcp -p tcp --dport 25 -j ACCEPT
  19. -A RH-Firewall-1-INPUT -s 192.168.1.1/254 -m state --state NEW -p tcp --dport 22 -j ACCEPT
  20. -A RH-Firewall-1-INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT

我现在只是试图允许从本地网络访问机器.

任何帮助将非常感激.谢谢.

编辑:

根据第一个答案,已将COMMIT移至文件末尾,但仍然收到错误

  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. -A RH-Firewall-1-INPUT -m tcp -p tcp --dport 80 -j ACCEPT
  14. -A RH-Firewall-1-INPUT -m tcp -p tcp --dport 53 -j ACCEPT
  15. -A RH-Firewall-1-INPUT -m udp -p tcp --dport 53 -j ACCEPT
  16. -A RH-Firewall-1-INPUT -m tcp -p tcp --dport 443 -j ACCEPT
  17. -A RH-Firewall-1-INPUT -m tcp -p tcp --dport 25 -j ACCEPT
  18. -A RH-Firewall-1-INPUT -s 192.168.1.0/255 -m state --state NEW -p tcp --dport 22 -j ACCEPT
  19. -A RH-Firewall-1-INPUT -m state --state NEW -p tcp --dport 21 -j ACCEPT
  20. COMMIT

错误

  1. [root@dbserver ~]# service iptables restart
  2. iptables: Flushing firewall rules: [ OK ]
  3. iptables: Setting chains to policy ACCEPT: filter [ OK ]
  4. iptables: Unloading modules: [ OK ]
  5. iptables: Applying firewall rules: iptables-restore: line 13 Failed
  6. [Failed]

解决方法

简单 – 您需要将COMMIT移动到文件末尾.

COMMIT告诉iptables您已完成声明并希望将配置发送到内核.它结束了你的声明.你告诉iptables要COMMIT,然后你在没有新声明的情况下给出新规则,因此你的错误.

编辑以包含顺风评论内容

这是您的配置的更新和工作(不一定是最佳)版本:http://gist.github.com/3818123.我将总结一些问题:

>您的输入链RH-Firewall-1-INPUT不存在.你是从其他地方复制和粘贴的吗?>您的一些规则在您的默认拒绝规则之后下降.即使语法采用,规则也行不通.> 192.168.1.1/254甚至没有接近有效的CIDR寻址.你的意思是192.168.1.0/24吗?>你有-A RH-Firewall-1-INPUT -m udp -p tcp,这没有任何意义 – 我假设你的意思是-A INPUT -m udp -p udp.

猜你在找的Linux相关文章