4

I am doing WEB development on Windows 10 operating system. For that purpose, I am running Debian Linux on QEMU. I want to use SSH to connect to the virtual machine, possibly with putty and in the same time testing my server by putting an URL like http://192.168.1.1/index.html in the Internet Browser.

My virtual machine is configured as follow:

  • nginx on port 80 and 443: HTTP and HTTPS
  • SSH for file transfer between my laptop and the virtual machine

I am not very familiar with QEMU or networking, I read a lot of things on that topic I don't understand the technical details. I just need to do basic WEB development, I tried the following configurations:


> *Attempt 1*
qemu-system-x86_64 -m 512 -drive format=qcow2,file=hard-drive-4G.qcow2 -accel hax -nic tap,ifname=TAP-WIN32

Here, I previously installed a TAP device on Windows and created a Network Bridge. With this solution, I believe that QEMU is used as a Bridged Networking. This solution seems to work at the beginning, but it's actually unstable. I shutdown my virtual machine every day when I leave the office and restart it the next morning. In a very weird fashion, after a few days of usage, the networking is not working anymore, SSH broken and HTTP also broken.

I haven't been able to figure out what is going wrong here (the IP address seems correct), but I assume they might be a conflict, maybe the DHCP is messing up with MAC addresses, I have absolutely no clue.

I observed 2 things:

Observation-1: when it's not working, I try from Debian to ping a website, I get a unable to resolve host error and the DHCP gives me the same IPv4 address on my virtual machine as as my Windows computer.

Observation-2: when it's working, ifup requested DHCP for a new IP, the virtual machine got an IP address which is different from the local IP address of my laptop. I just have no idea how long this working state is going to last.


> *Attempt 2*
qemu-system-x86_64 -m 512 -drive format=qcow2,file=hard-drive-4G.qcow2 -accel hax -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22

Here, SSH is available through putty (port 5555) but if I type http://10.0.2.15/index.html in my Internet browser, I get a connection timeout.


What is the simple way to get SSH and HTTP available from my QEMU virtual machine on Windows?

Robert
  • 195
  • 2
    Is qemu a requirement? VirtualBox is probably easier – Virsacer Feb 22 '22 at 07:21
  • 1
    Yes QEMU is preferred. Actually VirtualBox used to be much easier you are very correct. I just tried the last version, the bridged networking is not working at all on my computer. It used to work flawless, but it suddenly break on a recent VirtualBox update. – Robert Feb 22 '22 at 07:25

1 Answers1

3

I found a solution by merging together different pieces of the documentation. On this amazing Stackoverflow question, we learn the differences between several networking devices:

  • virtio
  • e1000
  • rtl8139

In summary, virtio is the fastest but the drivers may not be easily available. rtl8139 is fast and the drivers are easily available to most of operating systems. e1000 is the slowest among the 3, but the drivers are available to most of operating systems, even some weird ones.

So while virtio has the best performance, e1000 has the best compatibility. I am going to choose the virtio device.

In the comments section of another website, we can see how to chain multiple ports redirections:

-netdev user,id=ethernet.0,hostfwd=tcp::5555-:1522,hostfwd=tcp::9999-:9,hostfwd=tcp::17010-:17010,hostfwd=tcp::17013-:17013


When putting all together, we have a configuration which seems quite robust and stable:

qemu-system-x86_64 -m 512 -drive format=qcow2,file=hard-drive-4G.qcow2 -accel hax -netdev user,id=net0,hostfwd=tcp::8022-:22,hostfwd=tcp::8080-:80 -device virtio-net-pci,netdev=net0

The ports seems actually shared between the host and the virtual machine. So if one want to use SSH, running on port 22 on the virtual machine, it will be required to choose another port, let's say 8022 and redirect it to the port 22 of the virtual machine.

The same is done for port 80.

And finally:

  • SSH of the virtual machine is available from user@localhost:8022
  • HTTP of the virtual machine is available from http://localhost:8080

Note that internet is available from the virtual machine, but ICMP thing seems not to work, so ping commands are not working properly.

Robert
  • 195