Difference between -net user and -net nic in qemu

jobin picture jobin · Mar 26, 2014 · Viewed 11.4k times · Source

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?

Answer

6EQUJ5 picture 6EQUJ5 · Mar 28, 2014

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.