Skip to contentSkip to conversation

qemu.rst: slirp port forwarding details

PATCH Superseded Atanas Bunchev 2 participants 2 messages Nov 9, 2022

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qemu.rst: slirp port forwarding details

Explains the default behavior of runqemu slirp. Explains how to forward ports from the guest to the host machine.

---
 documentation/dev-manual/qemu.rst | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
documentation/dev-manual/qemu.rst +21 -0
index 5a4a82ce6..a17c8cead 100644
@@ -426,6 +426,27 @@ command line:
    networking that does not need root access but also is not as easy to
    use or comprehensive as the default.
 
+   Using ``slirp`` by default will forward the guest machine's
+   22 and 23 ports to host machine's 2222 and 2323, incrementing
+   them if they're already taken by another ``runqemu`` instance.
+   Specific forwarding rules can be configured by
+   setting ``QB_SLIRP_OPT`` in ``qemuboot.conf``.
+   Examples::
+
+      QB_SLIRP_OPT="-netdev user,id=net0,hostfwd=tcp::8080-:80"
+
+      QB_SLIRP_OPT="-netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22"
+
+   The first example forwards TCP port 80 from the emulated system to
+   port 8080 on the host system, allowing access to http server running in
+   QEMU from ``http://<host ip>:8080/``
+
+   The second example does the same, but also forwards port 22 to 2222, 
+   allowing ssh access to the emulated system using
+   ``ssh -P 2222 <user>@<host ip>``
+
+   Keep in mind that proper configuration of firewall software is required.
+
 -  ``kvm``: Enables KVM when running "qemux86" or "qemux86-64" QEMU
    architectures. For KVM to work, all the following conditions must be
    met:
Signature · 1 line
2.37.4
#1 lore raw

Hi Atanas,

Quoted 13 lines · Atanas Bunchev

Explains the default behavior of runqemu slirp. Explains how to forward ports from the guest to the host machine.

---
  documentation/dev-manual/qemu.rst | 21 +++++++++++++++++++++
  1 file changed, 21 insertions(+)
documentation/dev-manual/qemu.rst +0 -0
index 5a4a82ce6..a17c8cead 100644

documentation/dev-manual/qemu.rst command line: · line 430

Quoted 5 lines
documentation/dev-manual/qemu.rst +2 -0
@@ -426,6 +426,27 @@ command line:
     networking that does not need root access but also is not as easy to
     use or comprehensive as the default.
 
+   Using ``slirp`` by default will forward the guest machine's
+   22 and 23 ports to host machine's 2222 and 2323, incrementing

Please add "TCP" in front of ports (or somewhere adequate). UDP is not forwarded by default.

documentation/dev-manual/qemu.rst command line: · line 431

Quoted 1 line
documentation/dev-manual/qemu.rst +1 -0
+   them if they're already taken by another ``runqemu`` instance.

I'd replace
incrementing them if they're already taken by another runqemu instance by
or the next free port available.

because it checks if the port is available, it does not matter if it's a runqemu instance running or not.

documentation/dev-manual/qemu.rst command line: · line 443

Quoted 12 lines
documentation/dev-manual/qemu.rst +12 -0
+   Specific forwarding rules can be configured by
+   setting ``QB_SLIRP_OPT`` in ``qemuboot.conf``.
+   Examples::
+
+      QB_SLIRP_OPT="-netdev user,id=net0,hostfwd=tcp::8080-:80"
+
+      QB_SLIRP_OPT="-netdev user,id=net0,hostfwd=tcp::8080-:80,hostfwd=tcp::2222-:22"
+
+   The first example forwards TCP port 80 from the emulated system to
+   port 8080 on the host system, allowing access to http server running in
+   QEMU from ``http://<host ip>:8080/``
+

Missing dot at the end of the sentence.

Also, this is incorrect, because if 8080 is already taken, it'll try to find the next free port available similar to what's done for the default value. So a bit of rewording will be necessary to include this important piece of information.

On a side note, quite interestingly, we only check if the TCP port is taken even if a forwarding rule for UDP is added.

documentation/dev-manual/qemu.rst command line: · line 447

Quoted 4 lines
documentation/dev-manual/qemu.rst +4 -0
+   The second example does the same, but also forwards port 22 to 2222,
+   allowing ssh access to the emulated system using
+   ``ssh -P 2222 <user>@<host ip>``
+

Same remarks apply for this paragraph.

Cheers,
Quentin