在控制台上为Centos 6.3启用端口80上的http访问

在Parallels上运行一个Centos 6.3盒子

我试图打开80端口从外面访问

尝试从这篇文章的GUI解决scheme,它的工作原理,但我需要从脚本来完成它。

试图做到这一点:

sudo /sbin/iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT sudo /sbin/iptables-save sudo /sbin/service iptables restart 

这将创build与GUI工具完全相同的iptables条目,除非它不起作用:

 $ telnet xx.xxx.xx.xx 80 Trying xx.xxx.xx.xx... telnet: connect to address xx.xxx.xx.xx: Connection refused telnet: Unable to connect to remote host 

更新:

 $ netstat -ntlp (No info could be read for "-p": geteuid()=500 but you should be root.) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN - tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN - tcp 0 0 0.0.0.0:37439 0.0.0.0:* LISTEN - tcp 0 0 :::111 :::* LISTEN - tcp 0 0 :::22 :::* LISTEN - tcp 0 0 ::1:631 :::* LISTEN - tcp 0 0 :::60472 :::* LISTEN - $ sudo cat /etc/sysconfig/iptables # Generated by iptables-save v1.4.7 on Wed Dec 12 18:04:25 2012 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [5:640] -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 INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT # Completed on Wed Dec 12 18:04:25 2012 

我会说你的规则是在你的INPUT iptables列表的末尾。 试试这个iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT然后运行service iptables save 。 您的命令中的A将规则附加到当前的INPUT列表。 这是在一个可能有明确拒绝的规则之后。 我在我的命令中,将规则放在一个行的位置,在这种情况下第5行。哪个应该在默认的拒绝规则之前。 IPTABLES中的规则从上到下工作,如果规则匹配,则防火墙将规则应用于连接。 我使用这个 – iptables-rules-examples – 真的很有帮助

命令service iptables restart不保存你当前的iptables规则。

在重新启动之前执行service iptables save

规则匹配从上到下。 所以iptables在第一次匹配的时候做动作。 你有:

 -A INPUT -j REJECT --reject-with icmp-host-prohibited -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT 

第一条规则没有任何条件,所以没有可能达到第二条规则的数据包。