Saturday, October 12, 2019

Connect from Windows host to QEMU inside Docker

I am trying to establish a connection between Windows 10 running Docker container (Linux), which runs QEMU to host a QNX OS. This picture should make it more clear: Structure

I would like to highlight what I was able to reach so far:

  1. From the host, I can ping the the IP inside the docker container: 10.0.75.2
  2. From the docker container, I have established a tap interface and a VDE switch, and I can ping the QNX: 192.168.56.51

Commands used for initiating the environment: ```

add new network interface

ip tuntap add mode tap dev tap0 ip addr add 192.168.56.1/24 dev tap0 ip link set dev tap0 up

start vde switch connected to tap0

vde_switch -F -d -sock /tmp/myswitch -tap tap0

start QEMU

qemu-system-x86_64 \ -m 1024 \ -cpu qemu64 \ -smp 2 \ -netdev vde,id=t0,sock=/tmp/myswitch \ -device e1000,netdev=t0,mac=52:54:00:12:34:50 \ -drive file=/qnx/qnx_vm_x86_64-qemu.img \ -D /var/log/qemu_err.log \ -serial file:/var/log/qemu_out.log \ -display none -daemonize ```

Command to run the docker container: docker run -it --rm --network=host --cap-add=NET_ADMIN --privileged qemu_qnx

What is missing is to be able to connect between the host and the QNX. Is it possible for example to forward the connection from Hvint0 to Tap0?

Aside note: On Linux host, I can run the Docker container with network=host, and I can access it from the host easily, but unfortunately that wouldn't work on Windows host.

What I have tried so far unfortunately with no luck:

  1. Do port forwarding for the QNX guest: ``` #flush iptables rules iptables -F iptables -t nat -F

Add rule

iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination 192.168.56.51:22

Save the iptables rule :

sudo iptables-save | sudo tee /etc/iptables.up.rules

```

  1. Start QEMU with hostfwd option, I can see the port is opened but I cannot ssh into it (doubting it can also be related to QNX network settings) -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22

Please let me know if there might be any more information I can provide.



No comments:

Post a Comment