我是Centos的新手。 我需要在Centos中打开几个端口。
我search了一下,发现了这样的东西。
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT
但是当我尝试重新启动iptables时,会出现以下错误
iptables: Applying firewall rules: iptables-restore: line 13 failed
如何在Centos 6中打开端口?
如果你想打开一个单一的端口:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT
对于多个,你可以使用下面的代替(或重复上面的行多次):
-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80,143 -j ACCEPT
您的线路不工作的原因可能是因为您没有一个名为“RH-Firewall-1-INPUT”的链。 CentOS 6只是使用“INPUT”作为连锁名称。 您将在默认configuration的顶部注意到以下内容,命名存在的链:
:INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0]
只需要进一步解释一下-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT表示:
-A :附加一条规则 INPUT :input链 -m state :使用“状态”模块 --state NEW :只查找新的连接(即不是那些以前build立/相关的连接) -m tcp :使用tcp模块 -p tcp :使用TCP协议查找数据包 --dport 143 :查找目标端口为143的数据包 您可以通过添加以下内容
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
在22个港口之后
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
重新启动iptables,它应该工作,至less对我来说,它的工作。