我安装了几个虚拟机。一些在 Windows 下,一些在 Fedora Linux 下。在其中一台 Fedora 机器上,我安装了 Apache Web 服务器。
我在 httpd.conf 中将服务器名称设置为172.16.27.129:80
,确保对 html 目录的访问权限为Allow from all
,并用测试文件填充该目录.html
。启动 httpd 后,我的 Web 服务器已在本地运行。
然后我尝试从其他机器访问它,但失败了。只收到“Firefox 无法建立连接”消息。
服务器机器上的错误日志为空。我认为可能是防火墙的问题,因此我进行了如下 iptables 设置:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:https state NEW,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:http state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:https state ESTABLISHED
还是没运气。我以为是网络出了问题。但我的一台虚拟 Windows 机器上有一个通过 HTTPS 运行的 Subversion 服务器,所以网络应该没问题。
到现在为止我已经没什么主意了。我错过了什么?
更新:必须是 iptables。我刚把它关掉,一切就都正常了。
答案1
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
ACCEPT tcp -- anywhere anywhere tcp dpt:http state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:https state NEW,ESTABLISHED
这里的问题是,与 HTTP 和 HTTPS 流量有关的两行都紧跟在条目之后REJECT
,这意味着这些规则根本无法被看到。它们需要在之前放入 IPTABLES 配置中REJECT
,否则它们将被阻止。