我有一个虚拟机网络服务器设置,我已经安装并启动了 Apache。VM 具有桥接网络接口,可以使用 192.168.0.2 从主机 ping 通。
但是,如果我在主机上的浏览器中键入相同的 IP 地址,我希望看到在 VM 上生成的默认 apache 页面,但相反,我进入can't connect to 192.168.0.2
了主机浏览器。
我显然错过了一些东西。有谁知道我错过了什么或做错了什么?
虚拟机输出 netstat -tnlp
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 950/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1026/master
tcp 0 0 :::22 :::* LISTEN 904/sshd
tcp 0 0 ::1:25 :::* LISTEN 980/master
Run Code Online (Sandbox Code Playgroud)
粗略地画出我认为网络活动/连接的样子。
slm*_*slm 14
有3种网络模式:
Depending on which distro you're using, the firewall might be blocking your web browser from accessing your Apache instance. This would make sense given you're able to ping the system, but not access it via port 80, which is the port that Apache is listening on.
On CentOS you use this command to disable it.
$ /etc/init.d/iptables stop
Run Code Online (Sandbox Code Playgroud)
You can also confirm that it's listening on this port.
$ netstat -antp | grep :80 | head -1 | column -t
tcp 0 0 :::80 :::* LISTEN 3790/httpd
Run Code Online (Sandbox Code Playgroud)
The firewall can be confirmed that it's wide open.
$ iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Run Code Online (Sandbox Code Playgroud)
If this solves your issue then you can permanently add a rule that allows traffic in via TCP port 80.
$ /etc/init.d/iptables restart
$ iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
$ /etc/init.d/iptables save
Run Code Online (Sandbox Code Playgroud)
NOTE: This will make the rule persist between reboots.
A system that has the port 80 open would look something like this:
$ iptables -L
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 all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:https
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:8834
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Run Code Online (Sandbox Code Playgroud)
In the above issue we saw that Apache was listening, but sometimes it's mis-configured so that it's only listening on 1 IP address, or that it's listening on a different network interface. The command netstat
can be used to double check this as well as reviewing the Apache configuration files.
$ netstat -anpt | grep :80 | column -t
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1750/httpd
Run Code Online (Sandbox Code Playgroud)
This shows that Apache is listening on all interfaces (IP 0.0.0.0).
I won't repeat what @Lekensteyn's answer which covers this particular issue in more details here.
归档时间: |
|
查看次数: |
78827 次 |
最近记录: |