You are not logged in.

#1 2017-04-21 20:51:20

Me@Work
Member
Registered: 2016-10-03
Posts: 10

Network bridge for QEMU using netctl

Hello!


To install another linux distribution on top of my arch linux system I'm using QEMU:

qemu-system-x86_64 -enable-kvm -m 4G -cpu host -smp 2 -vga virtio -display sdl,gl=on -soundhw all -cdrom myimage.iso myvolume.raw

The host as well as the virtual machine have network access. In my case my host has the IP 192.168.100.20 and the VM the IP 10.0.2.15. Because I want to have my virtual machine accessible out of the native network NAT is no option. I would like to have network access from my host receiving his IP from a DHCP server and at the same time network access from my virtual machine with a user defined MAC adress. Furthermore the virtual machine should ask the DHCP server for an IP adress. Or in other words I'm looking for an behaviour like Virtual Box selecting Bridge Network.

  1. First I've created a network bridge and check if the network on the host still works:

    > cat /etc/netctl/bridge 
    Description="Example Bridge connection"
    Interface=br0
    Connection=bridge
    BindsToInterfaces=(eno1)
    IP=dhcp
    ## Ignore (R)STP and immediately activate the bridge
    #SkipForwardingDelay=yes
    > netctl start bridge
    > ifconfig
    br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.100.20  netmask 255.255.255.0  broadcast 192.168.100.255
    
    eno1: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
    
    > ping -c 1 www.google.de
    PING www.google.de (216.58.205.227) 56(84) bytes of data.
    64 bytes from fra15s24-in-f3.1e100.net (216.58.205.227): icmp_seq=1 ttl=56 time=31.6 ms
  2. Next I'm running QEMU:

    sudo qemu-system-x86_64 -enable-kvm -m 4G -cpu host -smp 2 -vga virtio -display sdl,gl=on -soundhw all -cdrom myimage.iso myvolume.raw -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no
    1. First problem is, that I'm not keen on executing QEMU with root privileges, but otherwise the network device tap0 won't be created. Startup- and shutdown scripts are also no option. I would like to preconfigure - if necessary as root - the network devices once for all users and than run QEMU as an ordinary user.

    2. As I've read on the internet, this should work as well, but it does not. I would like to know why.

      sudo qemu-system-x86_64 -enable-kvm -m 4G -cpu host -smp 2 -vga virtio -display sdl,gl=on -soundhw all -cdrom myimage.iso myvolume.raw -netdev tap,id=tap0 -device e1000,netdev=tap0
    3. And thirdly I would like to define in this scenario a certain MAC adress vor the virtual machine.

  3. Finally I'm configuring the network of the virtual machine in the virtual machine using the Network Manager, but the device does not get an IP adress. The biggest of all problems... wink

What I'm doing wrong? The Wiki for QEMU (https://wiki.archlinux.org/index.php/QEMU) and netctl (https://wiki.archlinux.org/index.php/Netctl resp. https://wiki.archlinux.org/index.php/Network_bridge) has not answered my questions or solved my problem.


Matthew

Last edited by Me@Work (2017-04-21 20:55:13)

Offline

#2 2017-04-22 19:14:57

Me@Work
Member
Registered: 2016-10-03
Posts: 10

Re: Network bridge for QEMU using netctl

Hello!


I have figured out on my own, what was my major mistake. The following setup works for me (Layer 2 Bridge for QEMU VM):

  1. Create a tap device (as root):

    > ip tuntap add name tap0 mode tap
    > ip link set tap0 master br0
    > ip link set up dev tap0
  2. Run the bridge (as root):

    > cat /etc/netctl/bridge
    Description="Example Bridge connection"
    Interface=br0
    Connection=bridge
    BindsToInterfaces=(eno1 tap0)
    IP=dhcp
    ## Ignore (R)STP and immediately activate the bridge
    #SkipForwardingDelay=yes
    > netctl start bridge
  3. Start the virtual machine and bind it to tap0 (as ordinary user):

    qemu-system-x86_64 -enable-kvm -m 4G -cpu host -smp 2 -vga virtio -display sdl,gl=on -soundhw all -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no -cdrom myimage.iso myvolume.raw

But three questions still have left:

  1. Is it - and if it is, how it is - possible to create the tap0 device as described in 1. with netctl?

  2. The MAC adresses of br0 and tap0 are matching each other, but ifconfig in the virtual machine itself shows up an other MAC adress. How can I specify the MAC adress for the VM outside the virtual machine (e.g. using ip link, netctl or a certain parameter for qemu-system-x86_64)?

  3. Would it make sense (performance, security, ...) running permanently this setup for being prepared if a user want's to run a VM with a bridged network or would it be better switching to this setup if needed?

Just for information for those who have the same question as I had: In the described setup the host has it's own network interface and it's own IP adress receiving from the DHCP server. The virtual machine has also it's own network interface but the IP adress is received from the virtual machine and not from the host for the virtual machine (in case I'm wrong, feel free to correct me).


Matthew

Last edited by Me@Work (2017-04-22 19:17:49)

Offline

Board footer

Powered by FluxBB