NetworkManager and Bridge and KVM
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/SuSEfirewall2FW_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.confenvy:/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
Update: Alternative mit Hilfe des nmcli commandline Tools
nmcli con add ifname br0 type bridge con-name br0
nmcli con add ifname eth0 type bridge-slave master br0
nmcli con add ifname wlan0 type bridge-slave master br0nmcli con show
NAME UUID TYPE DEVICE
br0 ebd091e0-2cf1-4f40-b4b4-d96aee8a25ae bridge br0
lo 7cb72a11-ec25-49aa-b1e0-23772f3b0a07 loopback lo
bridge-slave-eth0 86433fdd-1141-4989-ac8b-f93806451073 ethernet eth0
bridge-slave-wlan0 6d5ac343-4df4-432f-b15f-c89dc5e55542 ethernet —
eth0 7ba00b1d-8cdd-30da-91ad-bb83ed4f7474 ethernet —
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.
computersalat
Schreibe einen Kommentar
Du musst angemeldet sein, um einen Kommentar abzugeben.