【问题标题】:How can I share the localhost of my host computer with a QEMU image?如何与 QEMU 映像共享主机的 localhost?
【发布时间】:2021-08-03 20:04:55
【问题描述】:

想知道这样的事情是否可能:我有一台服务器正在侦听我本地 PC 的 localhost:1889,而我的 QEMU 映像能够使用相同的端口和 IP 访问服务器 - localhost:1889

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

  • 启用此功能的 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 - 虽然会避免它。

【问题讨论】:

    标签: iptables qemu portforwarding


    【解决方案1】:

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

    您不能将客户机中的“localhost”直接指向主机 PC,因为客户机的“localhost”就是客户机本身,将其指向其他地方可能会混淆客户机中运行的软件。

    【讨论】:

    • 想知道 iptables 对此的回答可能是什么
    • @Shodan 我很惊讶地发现这实际上可以在较新的内核上实现。 unix.stackexchange.com/q/266812 我想要做的就是将所有从访客到主机的流量注入到 localhost 环回中。
    • @jpaugh 我能够在 TAP 连接中使用 iptables 成功完成此操作。你说得对,QEMU 确实支持流量注入,但仅适用于 SLIRIP 连接
    猜你喜欢
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    • 2019-05-03
    • 1970-01-01
    • 1970-01-01
    • 2013-01-06
    • 2018-06-21
    相关资源
    最近更新 更多