2

Please consider the following scenario.

Host: Ubuntu 18.04 LTS desktop with latest updates. QEMU version 3.1.

Network managed by network-manager with working wireless connection to the Internet.

$ ifconfig
enp0s25: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether xx:xx:xx:xx:xx:xx  txqueuelen 1000  (Ethernet)
        RX packets 234  bytes 47490 (47.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 362  bytes 86199 (86.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 20  memory 0xf3b00000-f3b20000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Lokale Schleife)
        RX packets 120821  bytes 896665929 (896.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 120821  bytes 896665929 (896.6 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp3s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.5  netmask 255.255.255.0  broadcast 10.0.0.255
        inet6 xxxx::xxxx:xxxx:xxxx:xxxx  prefixlen 64  scopeid 0x20<link>
        ether yy:yy:yy:yy:yy:yy  txqueuelen 1000  (Ethernet)
        RX packets 3098974  bytes 3223048745 (3.2 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2259694  bytes 909739966 (909.7 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

KVM virtual machine: Freshly installed and updated Ubuntu Server 18.04 LTS with LAMP stack named uslamp.img.

The VM is launched with qemu-system-x86_64 -enable-kvm -m 6G -smp cores=3 -cpu host -drive file=uslamp.img,if=virtio,aio=native,cache.direct=on -vga virtio -usb -device usb-tablet -nic tap,model=virtio-net-pc


Please note that neither libvirt nor tools like uvtool or multipass should be used.


Issue: I can't get any working network connection to the host. Neither qemu-bridge-helper nor Ubuntu server guide or any of the proposals I read here in StackExchange provided a working solution.

Error message upon launch of the VM:

qemu-system-x86_64: could not configure /dev/net/tun: Operation not permitted

Launching the VM as root provides:

W: /etc/qemu-ifup: no bridge for guest interface found

Despite this warning the VM starts and is provided with an IP4 address only when the -nic option is discarded from the QEMU launch command. The VM's address can be pinged inside the VM running Ubuntu server. However there is no connection to the network, i.e. pinging the DNS at 10.0.0.1 results in 100% packet loss.


Modified /etc/netplan yaml file as per man pages:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
# MW
  ethernets:
    wlp3s0:
      dhcp4: no
  bridges:
    br0:
      dhcp4: yes
      interfaces:
        - wlp3s0

QEMU lauching with:

 sudo qemu-system-x86_64 -enable-kvm -m 6G -smp cores=3 -cpu host -drive file=uslamp.img,if=virtio,aio=native,cache.direct=on -vga virtio -usb -device usb-tablet -nic tap,model=virtio-net-pci,script=no

VM starts up and stops for ~2 minutes with A start job is running Wait for Network to be Configured.

On the host:

ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s25: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether f0:de:f1:ad:44:0a brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000
    link/ether 08:11:96:e6:a2:ac brd ff:ff:ff:ff:ff:ff
26: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
     link/ether 6a:1b:be:e2:9f:ec brd ff:ff:ff:ff:ff:ff
28: tap0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
     link/ether ea:d6:20:c8:e2:b5 brd ff:ff:ff:ff:ff:ff

VM has no assigned IP address and thus no connection to the Internet.

What am I missing?


Any advise highly appreciated!

0

if you don't specify -nic ... then qemu will add defaults which per man page:

If no -net option is specified, a single NIC is created.

Which is equivalent to -net nic -net user

So far you specified nic which means you created the virtual HW, but you have not yet connected it to anything.

Assuming you have setup a bridge for it already you need to tell qemu to connect to that.

But let me warn you, IIRC bridging onto wireless devices wasn't always working great. It should have changed nowadays, but be aware that depending which doc/blog you read you might get outdated info.

To connect to a bridge you'll find on the same man page sequences like -net nic -net tap,"helper=/path/to/qemu-bridge-helper" or -net bridge[,vlan=n][,name=name][,br=bridge][,helper=helper]

-netdev is newer and lets you do the same, but at once - but you still need to couple it with a device. See here for more about that.

Some of the actions to create the tap network to bind to the bridge need root permissions which is what you have seen. So you can either run as root (not recommended) or setup an qemu-ifup script for your needs. The default for that script is already in /etc/qemu-ifup by package qemu-system-common.

That should help you resolve your setup issue, but I really want to mention that libvirt would do all that messing with qemu command-line and net prep for you? And if you hate XML files let uvtool do it for you. Or if you don't like libvirt consider multipass which will also do all of that for you (but by default without libvirt).

P.S. even if you just wanted to run qemu manually, consider using the tools I mentioned above and check how they set up the networking in qemu's commandline.

| improve this answer | |
  • I tried the helper (per documentation) - doesn't work unfortunately. – mgw May 22 '19 at 9:47
  • As of QEMU version 3 "The following two example do exactly the same, to show how -nic can be used to shorten the command line...": -netdev user,id=n1,ipv6=off -device e1000,netdev=n1,mac=52:54:98:76:54:32 and -nic user,ipv6=off,model=e1000,mac=52:54:98:76:54:32 – mgw May 22 '19 at 9:58
  • Modified question with additional information MW – mgw May 22 '19 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.