Difference between -net user and -net nic in qemu

13,987

To anwser your last question first, you need both options:

qemu <other options> -net nic[,options] -net user[,options]
  • The nic option enables the network card in the guest.
  • The user option sets up a virtual NAT'ted subnet, with a DHCP server started by qemu that gives out (usually) 10.0.2.15 to your guest and puts the host on 10.0.2.2.

With this configuration your guest can see the Internet and can also connect to services on the host at 10.0.2.2

If you want to access services on the guest you need to use hostfwd

qemu <other options> -net user,hostfwd=tcp::60022-:22

This will let you do the following to access ssh on the guest from the host:

ssh -p60022 user@localhost

The options to -net nic you can use to change the type of network card from the default for the qemu platform in use. For example if your guest is running an older operating system you might prefer to use -net nic,model=ne2k_pci over the default e1000.

To use a custom IP address you need to follow the tutorials that make a bridge and connect both your host and guest. The -net user option is far simpler if you just want to run up a guest to do some work in a different O/S.

Share:
13,987
jobin
Author by

jobin

Updated on June 14, 2022

Comments

  • jobin
    jobin almost 2 years

    I am trying to boot a virtual machine with my a custom IP address using qemu-system-x86_64. Referring to qemu-system-x86_64's tutorials, I found this:

    -net nic[,vlan=n][,macaddr=mac][,model=type] [,name=name][,addr=addr][,vectors=v] Create a new Network Interface Card and connect it to VLAN n (n = 0 is the default). The NIC is an e1000 by default on the PC target. -netdev user,id=id[,option][,option][,...]

    -net user[,option][,option][,...]
        Use the user mode network stack which requires no administrator privilege to run. 
    

    I am not able to understand the difference between these two options.

    • What is a user mode network stack?
    • And why do I need it?
    • What is the difference between the nic and user parameters?
  • Chan Kim
    Chan Kim over 9 years
    The -net nic option sounds like the qume-system generates a nic for me.(is it right?) If I have an nic emulator instanticated (for example, by adding smsc9220 model) then should I still give -net nic option?