Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between -net user and -net nic in qemu

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?
like image 378
jobin Avatar asked Mar 26 '14 07:03

jobin


People also ask

What is QEMU Nic?

< QEMU. QEMU supports networking by emulating some popular network cards (NICs), and establishing virtual LANs (VLAN). There are four ways that QEMU guests can be connected: user mode, socket redirection, Tap and VDE networking.

What is difference between KVM and QEMU?

So to conclude: QEMU is a type 2 hypervisor that runs within user space and performs virtual hardware emulation, whereas KVM is a type 1 hypervisor that runs in kernel space, that allows a user space program access to the hardware virtualization features of various processors.

Does QEMU require hardware virtualization?

QEMU can emulate a complete machine in software without requiring any hardware virtualization support. Although this is a much less performant method of virtualization, it removes any potential conflicts with the underlying hardware, as QEMU 5.0 supports x86, PowerPC, ARM and SPARC architectures.

Is QEMU faster than VirtualBox?

VirtualBox is faster and has a better UI than QEMU. It's also a good choice only for x86 and x64 architectures.


1 Answers

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.

like image 106
6EQUJ5 Avatar answered Sep 28 '22 04:09

6EQUJ5