NetworkManager and Bridge and KVM

21. Dezember 2014 oremilac Linux

openSuSE 12.3 i.v.m. NetworkManager, Network Bridge und KVM Virtualisierung

Dieser Artikel soll eine Hilfestellung geben, wie man mit einem Laptop ‚virtualisieren‘ (KVM) kann, die VM’s an eine ‚Bridge hängen‘ und trotzdem die Vorzüge von NetworkManager nutzen kann, wenn man häufig in unterscheidlichen ‚WLANs‘ unterwegs ist.

Warum: Networkmanger macht den Zugange zum WLAN einfach. Man muß nicht ständig das Netzwerk umkonfigurieren. Aber NetworkManager unterstützt von Hause aus (derzeit) keine ‚Bridge‘ interfaces.

Lösung: Man erstellt trotzdem eine ‚Bridge‘ mit eigener IP und eigenem Netz. An diese ‚Bridge‘ werden dann die Netzwerkinterfaces der VM’s verbunden, d.h. die ‚Bridge‘ dient als ‚Gateway‘ für die VM’s. Da die ‚Bridge‘ ein eigenes, unabhängiges Netz anbietet, ist die VM immer vom Laptop aus erreichbar. Damit die VM auch automatisch die richtige Netzwerkkonfiguration bekommt, verwenden wir ‚dnsmasq‘ auf der ‚Bridge‘.

Alle Details zu meinen Konfigurationen folgen nun:

  • Anpassungen von SuSEfirewall2
    /etc/sysconfig/SuSEfirewall2

    FW_DEV_EXT="eth0 wlan0"
    FW_DEV_INT="br0 vnet0"
    FW_ROUTE="yes"
    FW_MASQUERADE="yes"
    FW_MASQ_NETS=""
    FW_PROTECT_FROM_INT="no"
    
  • Anpassungen an dnsmasq und service aktivieren
    /etc/dnsmasq.conf

    envy:/etc # diff -ruN dnsmasq.conf.orig dnsmasq.conf
    --- dnsmasq.conf.orig   2013-12-17 17:00:13.000000000 +0100
    +++ dnsmasq.conf        2013-12-16 23:25:20.000000000 +0100
    @@ -38,7 +38,7 @@
     # to  be  up.  Uncommenting this forces dnsmasq to try each query
     # with  each  server  strictly  in  the  order  they   appear   in
     # /etc/resolv.conf
    -#strict-order
    +strict-order
     
     # If you don't want dnsmasq to read /etc/resolv.conf or any other
     # file, getting its servers from this file instead (see below), then
    @@ -92,7 +92,7 @@
     #except-interface=
     # Or which to listen on by address (remember to include 127.0.0.1 if
     # you use this.)
    -#listen-address=
    +listen-address=192.168.58.1
     # If you want dnsmasq to provide only DNS service on an interface,
     # configure it as shown above, and then use the following line to
     # disable DHCP and TFTP on it.
    @@ -105,7 +105,7 @@
     # want dnsmasq to really bind only the interfaces it is listening on,
     # uncomment this option. About the only time you may need this is when
     # running another nameserver on the same machine.
    -#bind-interfaces
    +bind-interfaces
     
     # If you don't want dnsmasq to read /etc/hosts, uncomment the
     # following line.
    @@ -138,7 +138,7 @@
     # a lease time. If you have more than one network, you will need to
     # repeat this for each network on which you want to supply DHCP
     # service.
    -#dhcp-range=192.168.3.100,192.168.3.200,12h
    +dhcp-range=192.168.58.20,192.168.58.29,12h
     
     # This is an example of a DHCP range where the netmask is given. This
     # is needed for networks we reach the dnsmasq DHCP server via a relay
    
  • und das Script, welches uns beim Start die ‚Bridge‘ anlegt
    /sbin/nmbridge.sh

    #!/bin/bash
    
    brname='br0'
    
    add_br() {
      /sbin/brctl addbr $brname
      /sbin/brctl stp $brname on
      /sbin/brctl setfd $brname 0
      ifconfig $brname 192.168.58.1
      ifconfig $brname up
      /sbin/service dnsmasq restart
    }
    
    del_br() {
      /sbin/service dnsmasq stop
      ifconfig $brname down
      /sbin/brctl delbr $brname
    }
    
    del_br 2>/dev/null
    add_br
    
  • Und das Service File, welches für einen automatischen Start sorgt
    /usr/lib/systemd/system/nmbridge.service

    [Unit]
    Description=NM Bridge
    Requires=network.target
    After=network.target
    
    [Service]
    Type=simple
    ExecStart=/sbin/nmbridge.sh
    
    [Install]
    WantedBy=multi-user.target
    

Fazit: Es kann zu Netzwerkproblemen kommen, wenn eth0 oder wlan0 im selben Netz wie die ‚Bridge‘ sind
192.168.58.0/24

Anregungen und Verbesserungen sind gerne gesehen und willkommen.


Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

Powered by WordPress. Designed by elogi.