Home > Back-end >  How to emulate QEMU to connect server sockets
How to emulate QEMU to connect server sockets

Time:01-06

I have set up a QEMU virtual machine (VM) trying to emulate an ARM Cortex-A9 cpu on my lubuntu VM (on VirtualBox). Using the kernel, initrd and image of this article, I start QEMU like this:

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,hostfwd=tcp::5555-:22

After it boots up, I have configurated an static IP on the guest. Modifying the path /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.

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

Following @Peter Maydell advice i changed the network configuration to run a dhcp client instead of an 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. 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.

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.

CodePudding user response:

You can't just pick an IP address at random for your guest. 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. It will not (and should not be) on the same IP range as the host or this other VM. 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.

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. If you can't do that then you need to fix that VM's config first. 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. 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. It's only inbound connections to the QEMU guest that need hostfwd setup.

  • Related