端口转发到虚拟机 qemu
我最近在 Ubuntu 11.10 下安装了一个虚拟机,现在,我假设它正在使用 NAT,其内部地址是 192.168.122.88。
我在虚拟机中设置了一个 Web 服务器,并且希望在访问 192.168.122.88 时能够访问它。然而,现在它超时了。当我登录到虚拟机并尝试访问本地主机时,它可以工作。
因此,由于某种原因,我的 iptables 阻止了从主机到虚拟机的流量(但反之则不然)。
如何允许流量从我的主机流向我的虚拟机,以便我可以从主机看到网络服务器?
我使用带有 KVM 和 libvirt 的 Ubuntu 虚拟机管理器。
我尝试做这样的事情
iptables -t nat -A PREROUTING -d 192.168.0.10 -p tcp --dport 80 -j DNAT --to-destination 192.168.122.88:80
但没有成功。显然它说没有路由到主机?
I recently installed a Virtual Machine under Ubuntu 11.10, Right now, I assume, it is using NAT and its internal address is 192.168.122.88.
I have setup a web server in my virtual machine and I want to be able to access it when I go to 192.168.122.88 . However, right now it times out. When I log in to the virtual machine and try to access localhost it works.
So, for some reason, my iptables
is blocking traffic from the host to the virtual machine (But not the other way around).
How can I allow traffic to flow from my host to my vm so I can see the webserver from the host?
I used Ubuntu Virtual Machine Manager w/KVM and libvirt.
I tried doing someting like this
iptables -t nat -A PREROUTING -d 192.168.0.10 -p tcp --dport 80 -j DNAT --to-destination 192.168.122.88:80
with no avail. Apparently it says there is no route to host??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“没有到主机的路由”意味着主机没有可以与您尝试访问的网络相匹配的 IP 地址(甚至没有默认路由),请确保主机上有两个网络。
例如:
在 KVM 主机上,我将虚拟接口附加到某个网桥。例如:
然后,我为主机上的网桥分配一个 IP 地址,并将其设置为:
在我的虚拟机上,我在子网上分配一些 IP 地址,如 192.168.0.2,然后它们之间的 ping 应该成功。
'No route to host' means that the host machine doesn't have a IP address that can match the net you are trying to reach (you even don't have a default route), assure you have both nets on the host.
For example:
On KVM host machines, I attach the virtual interfaces to some bridge. For example:
Then, I assign an IP address to the bridge on the host, and set it on up:
On my virtual machine, I assign some IP address on the subnet like 192.168.0.2, then the ping should be successful between them.
也许您需要允许转发到虚拟机的连接。试试这个:
希望这有帮助。
Maybe you need to allow forwarded connections to the virtual machines. Try this:
Hope this helps.