如何与QEMU映像共享主机的本地主机? [英] How can I share the localhost of my host computer with a QEMU image?

查看:83
本文介绍了如何与QEMU映像共享主机的本地主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否可能发生这种情况:我有一台服务器正在侦听本地PC的 localhost:1889 ,并且我的QEMU映像能够使用相同的端口和IP访问该服务器-<代码>本地主机:1889 .

Was wondering if such a thing is possible: I have a server listening on localhost:1889 of my local PC and my QEMU image is able to access the server using the same port and IP - localhost:1889.

真正寻找以下任何一种解决方案:-

Really looking any one of the following solutions:-

  • 启用此功能的QEMU标志.这是我当前的命令:
 qemu-system-aarch64 -nographic -machine virt,gic-version=max -m 2058M -cpu cortex-a57 \
  -netdev user,id=net0,net=192.168.76.0/24 \
  -device virtio-net-pci,netdev=net0 \
  -drive file=ubuntu-image.img,if=none,id=drive0,cache=writeback \
  -device virtio-blk,drive=drive0,bootindex=0 \
  -drive file=flash0.img,format=raw,if=pflash -drive file=flash1.img,format=raw,if=pflash 

  • 一连串的iptables-尽管可以避免.
  • 推荐答案

    运行用户模式"网络(如您的命令行示例)的QEMU映像已经可以访问主机了.它可以通过主机具有的任何(非环回)IP地址或使用特殊的网关" IP地址来访问它.如果您使用默认的10.0.2.0/24网络设置,则网关"为10.0.2.2.我尚未确认,但怀疑对于非默认网络设置,它仍将位于.2,因此在此示例中为192.168.76.2.

    A QEMU image running the 'user-mode' networking (as in your command line example) already has access to the host machine. It can access it either via any (non-loopback) IP address the host has, or by using the special 'gateway' IP address. If you're using the default 10.0.2.0/24 network setting then the 'gateway' is 10.0.2.2. I haven't confirmed but suspect that for a non-default net setting it will still be on .2, so in this example 192.168.76.2.

    您不能从字面上将来宾中的本地主机"指向主机PC,因为来宾中的本地主机"是来宾本身,而将其指向其他位置则可能会使来宾中运行的软件感到困惑.

    You cannot literally make 'localhost' in the guest point to the host PC, because 'localhost' for the guest is the guest itself, and having it point somewhere else would likely confuse software running in the guest.

    这篇关于如何与QEMU映像共享主机的本地主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆