主机访问虚拟机中linux上的web服务

centos上使用的httpd服务是运行在VM中

网络:centos使用的是静态地址192.168.137.2  虚拟机使用的NAT连接方式,Vmnet8的地址是192.168.137.1,并将本地连接共享给Vmnet8,以便于centos使用

在httpd下下config文件中的http.conf  /etc/httpd/config/http.config 文件中 添加LISTEN 192.168.137.2:80条目

启动service httpd

此时centos中的浏览器应该就可以使用192.168.137.2了

但是,主机不能访问

继续添加防火墙规则

[root@localhost sbin]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@localhost sbin]# /etc/rc.d/init.d/iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables:     [确定]
[root@localhost sbin]# /etc/init.d/ip
ip6tables  iptables
[root@localhost sbin]# /etc/init.d/iptables restart
iptables:清除防火墙规则:                                 [确定]
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:正在卸载模块:                                   [确定]
iptables:应用防火墙规则:                                 [确定]

此时可以在主机浏览器中访问虚拟机中的web服务了

posted @ 2013-06-18 21:33  CN.QS  阅读(776)  评论(0编辑  收藏  举报