This blog post will explain how to forward ports with Qemu. If a guest machine is to be utilized as a server, the host operating system should have a way to connect to it. This example will boot a hard disk image. First a network device has to be defined by using -device e1000,netdev=vmnic in the command line arguments. Then a network interface card and the ports to be forwarded is defined by using -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:22-:22,hostfwd=tcp:127.0.0.1:80-:80 in the command line arguments. This will allow the host to access the guest with a ssh client or web browser.
qemu-system-x86_64 -M q35 -m 2G -hda debian-12.2.0-amd64-DVD-1.qcow2 -usbdevice tablet -device e1000,netdev=vmnic -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:22-:22,hostfwd=tcp:127.0.0.1:80-:80
The Windows version of QEMU was used for writing this blog post.