12

I have a script starting qemu with these options:

qemu-system-x86_64 [...]
                    -net nic,model=rtl8139
                    -net user,hostfwd=tcp::5555-:1522
                    -net dump,file=/tmp/vm0.pcap
                    -redir tcp:9999::9
                    -redir tcp:17010::17010
                    -redir tcp:17013::17013

I want to update the script to work with modern qemu options.

I've tried with the following arguments, as documented in the manual page

qemu-system-x86_64 [...]
                     -net nic,model=rtl8139
                     -net dump,file=/tmp/vm0.pcap
                     -net user,id=tcp1522,hostfwd=tcp::5555-:1522
                     -netdev user,id=tcp9,hostfwd=tcp::9999-:9
                     -netdev user,id=tcp17010,hostfwd=tcp::17010-:17010
                     -netdev user,id=tcp17013,hostfwd=tcp::17013-:17013

but the guest cannot reach the network anymore and it cannot be reached by the host on the forwarded ports.

What's the exact equivalent of the deprecated -redir option?

Bachelar Hu
  • 100
  • 1
  • 5
Giacomo Tesio
  • 7,144
  • 3
  • 31
  • 48
  • You have a couple of problems here: (1) you can't mix old-style -net with new-style -netdev+-device : use exclusively one or the other (2) I think that every "-netdev user,..." you add here is creating a new network backend, whereas you want to have one network backend whihc has multiple hostfwd rules. – Peter Maydell Sep 04 '17 at 18:44
  • @PeterMaydell you are right! Properly defining a single -netdev with several forwards and an unique id and defining a -device with that id as netdev fixed the issue. Please, turn your comment to an answer so that I can accept it. – Giacomo Tesio Sep 04 '17 at 21:03
  • You should write an answer yourself with the complete correct command line and accept it I think. – Peter Maydell Sep 05 '17 at 09:15

1 Answers1

13

After @PeterMaydell comments and a few more readings I understood how the options -device and -netdev relates in qemu.

The correct translation of the older -redir options used in my script are:

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

In a -netdev user you specify all host->guest port forwards for a single virtual ethernet of the guest. The id option identify such virtual network interface (ethernet.0 in this case).

The -device argument can then define the hardware to simulate for that interface (related with netdev=ethernet.0) so that the guest see that hardware in place and open the forwarded ports.

Giacomo Tesio
  • 7,144
  • 3
  • 31
  • 48
  • I tried the same but ssh command gets stuck, any idea what might be going wrong? I have a linux host with qemu vm and I am trying to connect ssh from linux to qemu – Sukumar Gaonkar Nov 15 '19 at 13:54