简体   繁体   English

如何模拟QEMU连接服务器sockets

[英]How to emulate QEMU to connect server sockets

I have set up a QEMU virtual machine (VM) trying to emulate an ARM Cortex-A9 cpu on my lubuntu VM (on VirtualBox).我已经设置了一个 QEMU 虚拟机 (VM),试图在我的 lubuntu VM(在 VirtualBox 上)上模拟 ARM Cortex-A9 cpu。 Using the kernel, initrd and image of this article , I start QEMU like this:使用本文的 kernel、initrd 和图像,我像这样启动 QEMU:

qemu-system-arm -M vexpress-a9 -cpu cortex-a9
    -m 512 
    -kernel vmlinuz-3.2.0-4-vexpress 
    -initrd initrd.img-3.2.0-4-vexpress 
    -drive if=sd,file=debian_wheezy_armhf_standard.qcow2 
    -append "root=/dev/mmcblk0p2" 
    -nic user,id=hostnet0,hostfwd=tcp::5555-:22

After it boots up, I have configurated an static IP on the guest.启动后,我在来宾上配置了一个 static IP。 Modifying the path /etc.network/interfaces .修改路径/etc.network/interfaces

auto eth0
iface eth0 inet static
    address 192.168.0.102
    netmask 255.255.255.0
    gateway 192.168.0.11

The VM lubuntu, is on the same IP range (192.168.0.1) and my goal is to be able to stablish a connection from QEMU VM to three server sockets which are on port 12000, 13000 and 14000 on the lubuntu VM. VM lubuntu 位于相同的 IP 范围 (192.168.0.1),我的目标是能够建立从 QEMU VM 到三台服务器 sockets 的连接,这三台服务器位于 lubuntu VM 的端口 12000、13000 和 14000 上。

Which parameters do i have to modify/add?我必须修改/添加哪些参数? I've been reading the network documentation but any test i do, is not working.我一直在阅读网络文档,但我所做的任何测试都不起作用。

UPDATE 1更新 1

Following @Peter Maydell advice i changed the.network configuration to run a dhcp client instead of an static IP.按照@Peter Maydell 的建议,我更改了 .network 配置以运行 dhcp 客户端而不是 static IP。

# /etc/network/interfaces

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

So when running # ip a i get the IP 10.0.2.15/24.所以当运行# ip a时,我得到 IP 10.0.2.15/24。 But now, there are some weird problems.但是现在,出现了一些奇怪的问题。

From host, I can ssh the QEMU VM doing ssh root@localhost -p 5555 but when i ping the IP 10.0.2.15 i get no response.从主机,我可以 ssh QEMU VM 执行ssh root@localhost -p 5555但是当我 ping IP 10.0.2.15 时,我没有得到任何响应。

From the lubuntu VM I can ping the QEMU VM with ping 10.0.2.15 but, from the QEMU VM I only have visibility to the host.从 lubuntu VM 我可以使用ping 10.0.2.15 ping QEMU VM 但是,从 QEMU VM 我只能看到主机。

You can't just pick an IP address at random for your guest.您不能随便为客人选择一个 IP 地址。 It has to match the fake.network that user-mode.networking creates, which is (as the wiki page you link to mentions) on 10.0.2.x by default.它必须与 user-mode.networking 创建的 fake.network 相匹配,默认情况下(作为您链接到提及的 wiki 页面)在 10.0.2.x 上。 It will not (and should not be) on the same IP range as the host or this other VM.它不会(也不应该)与主机或其他 VM 在相同的 IP 范围内。 The simplest thing is to have the guest run a DHCP client, which will then be able to automatically pick up the right.network config from the fake DHCP server that the user-mode.networking sets up.最简单的方法是让来宾运行一个 DHCP 客户端,然后它将能够自动从 user-mode.networking 设置的虚假 DHCP 服务器中获取正确的网络配置。

Cross-VM communication as you want should be doable.您想要的跨虚拟机通信应该是可行的。 First check that you can connect from the host to those ports on the lubuntu VM.首先检查您是否可以从主机连接到 lubuntu VM 上的那些端口。 If you can't do that then you need to fix that VM's config first.如果您不能这样做,那么您需要先修复该 VM 的配置。 Once that is working, then it should also work to connect from the in-QEMU guest to the lubuntu VM on the same IP address/port.一旦它开始工作,那么它也应该可以在相同的 IP 地址/端口上从 in-QEMU 来宾连接到 lubuntu VM。 This is because outbound connections from the QEMU user-mode.networked guest to either the host or to the outside world require no special configuration.这是因为从 QEMU user-mode.networked guest 到主机或外部世界的出站连接不需要特殊配置。 It's only inbound connections to the QEMU guest that need hostfwd setup.只有到 QEMU 访客的入站连接才需要 hostfwd 设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM