应用防火墙规则:iptables-restore:第49行失败

时间:2016-08-22 05:27:37

标签: centos iptables

我试图运行以下行 echo “-A INPUT -p tcp -m tcp --dport 3000 -j ACCEPT” >> /etc/sysconfig/iptables && sudo /etc/init.d/iptables restart

但是我收到以下错误:

iptables: Applying firewall rules: iptables-restore: line 49 failed [FAILED]

这是我的iptables文件

# Generated by iptables-save v1.4.7 on Wed Aug 17 19:21:57 2016
*nat
:PREROUTING ACCEPT [55:3224]
:POSTROUTING ACCEPT [696:43973]
:OUTPUT ACCEPT [696:43973]
COMMIT
# Completed on Wed Aug 17 19:21:57 2016
# Generated by iptables-save v1.4.7 on Wed Aug 17 19:21:57 2016
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:cP-Firewall-1-INPUT - [0:0]
-A INPUT -j cP-Firewall-1-INPUT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j cP-Firewall-1-INPUT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 53 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 995 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2083 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2079 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 993 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2077 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2095 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2096 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2082 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2080 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 26 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 465 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2086 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2087 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 110 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 2078 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 143 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A cP-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 587 -j ACCEPT
-A cP-Firewall-1-INPUT -p udp -m state --state NEW -m udp --dport 53 -j ACCEPT
COMMIT
# Completed on Wed Aug 17 19:21:57 2016
“-A INPUT -p tcp -m tcp --dport 3000 -j ACCEPT”
“-A INPUT -p tcp -m tcp --dport 3000 -j ACCEPT”

我正在运行centos 6.8

1 个答案:

答案 0 :(得分:0)

引号是问题,在最终COMMIT

之后也应该没有

您可以运行iptables -A INPUT -p tcp -m tcp --dport 3000 -j ACCEPT然后iptables-save将规则附加到相应的链。

如果必须编辑/ etc / sysconfig / iptables文件,请使用vim或vi编辑,并在第18行插入规则。

如果您需要将这些规则添加到cP-Firewall-1-INPUT,请将INPUT替换为cP-Firewall-1-INPUT,以便命令为iptables -A cP-Firewall-1-INPUT -p tcp -m tcp --dport 3000 -j ACCEPT