Bearbeiten von „VLAN for virtual machines“

Wechseln zu: Navigation, Suche

Warnung: Du bist nicht angemeldet. Deine IP-Adresse wird öffentlich sichtbar, falls du Bearbeitungen durchführst. Sofern du dich anmeldest oder ein Benutzerkonto erstellst, werden deine Bearbeitungen zusammen mit anderen Beiträgen deinem Benutzernamen zugeordnet.

Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und speichere dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version Dein Text
Zeile 6: Zeile 6:
 
and document it here.
 
and document it here.
  
In gerneral I will look at three methods:
+
In gerneral I will look at four methods:
 
# [[#oldstyle linux bridge as hub|oldstyle linux bridge as hub]]
 
# [[#oldstyle linux bridge as hub|oldstyle linux bridge as hub]]
 
# [[#linux bridge as hub|linux bridge as hub]]
 
# [[#linux bridge as hub|linux bridge as hub]]
 
# [[#linux bridge with libvirt hook scripts|linux bridge with libvirt hook scripts]]
 
# [[#linux bridge with libvirt hook scripts|linux bridge with libvirt hook scripts]]
 +
# [[#Open vSwitch|Open vSwitch]]
  
 
== Preparation ==
 
== Preparation ==
Zeile 208: Zeile 209:
 
== linux bridge with libvirt hook scripts ==
 
== linux bridge with libvirt hook scripts ==
 
We setup a bridge with VLAN enabled:
 
We setup a bridge with VLAN enabled:
  '''harley$''' cat /etc/systemd/network/08-br0.netdev  
+
  '''harley$''' cat 08-br0.netdev  
 
  [NetDev]
 
  [NetDev]
 
  Name=br0
 
  Name=br0
Zeile 216: Zeile 217:
 
  VLANFiltering=true
 
  VLANFiltering=true
 
  STP=false
 
  STP=false
  '''harley$''' cat /etc/systemd/network/12-br0_add-enp1s0.network  
+
  '''harley$''' cat 12-br0_add-enp1s0.network  
 
  [Match]
 
  [Match]
 
  Name=enp1s0
 
  Name=enp1s0
Zeile 227: Zeile 228:
 
  [BridgeVLAN]
 
  [BridgeVLAN]
 
  VLAN=30
 
  VLAN=30
  '''harley$''' cat /etc/systemd/network/16-br0_up.network  
+
  '''harley$''' cat 16-br0_up.network  
 
  [Match]
 
  [Match]
 
  Name=br0
 
  Name=br0
Zeile 259: Zeile 260:
 
# [[#set VLAN-ID to the dynamic virtual network interface vnet*]]
 
# [[#set VLAN-ID to the dynamic virtual network interface vnet*]]
 
<span id="debug.sh">For debugging the hook-scripts</span> I've made a small script:
 
<span id="debug.sh">For debugging the hook-scripts</span> I've made a small script:
  '''harley$''' cat /etc/libvirt/hooks/debug.sh
+
  '''harley$''' cat debug.sh
 
  #!/bin/bash -e
 
  #!/bin/bash -e
 
  # https://www.libvirt.org/hooks.html
 
  # https://www.libvirt.org/hooks.html
Zeile 290: Zeile 291:
 
=== get information on startup from the runtime XML-config of the domain ===
 
=== get information on startup from the runtime XML-config of the domain ===
 
It seems a little bit difficult to get needed information out of the big XML-config but it's no problem with XSLT. I've made a XSL-stylesheet for this and use xmlstarlet. Start a virtual machine and then its runtime configuration is available with <code>'''harley$''' virsh dumpxml deb9-test | xmlstarlet tr qemu.xsl</code>. With this I can test my stylesheet. Here is it:
 
It seems a little bit difficult to get needed information out of the big XML-config but it's no problem with XSLT. I've made a XSL-stylesheet for this and use xmlstarlet. Start a virtual machine and then its runtime configuration is available with <code>'''harley$''' virsh dumpxml deb9-test | xmlstarlet tr qemu.xsl</code>. With this I can test my stylesheet. Here is it:
  '''harley$''' cat /etc/libvirt/hooks/qemu.xsl  
+
  '''harley$''' cat qemu.xsl  
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  <?xml version="1.0" encoding="UTF-8"?>
 
  &lt;!-- This stylesheet extracts the VLAN-ID and the target device of the
 
  &lt;!-- This stylesheet extracts the VLAN-ID and the target device of the
Zeile 383: Zeile 384:
  
 
== Workaround for setting DefaultPVID=none ==
 
== Workaround for setting DefaultPVID=none ==
<span style="color:red">We do not need it anymore. This bug is fixed in systemd 234.</span>
 
 
 
Setting [https://www.freedesktop.org/software/systemd/man/systemd.netdev.html#DefaultPVID= DefaultPVID] in a<code>systemd-networkd</code> configuration file to "none" does not work. Until this bug is fixed I've made a workaround. The kernel accepts setting <code>default_pvid</code> to 0 (means "none") only if <code>vlan_filtering=0</code>, so we have to do:
 
Setting [https://www.freedesktop.org/software/systemd/man/systemd.netdev.html#DefaultPVID= DefaultPVID] in a<code>systemd-networkd</code> configuration file to "none" does not work. Until this bug is fixed I've made a workaround. The kernel accepts setting <code>default_pvid</code> to 0 (means "none") only if <code>vlan_filtering=0</code>, so we have to do:
 
  '''harley$''' sudo bash -c 'echo 0 >/sys/class/net/br0/bridge/vlan_filtering'
 
  '''harley$''' sudo bash -c 'echo 0 >/sys/class/net/br0/bridge/vlan_filtering'
Zeile 408: Zeile 407:
 
  '''harley$''' sudo chmod 744 /etc/systemd/network/DefaultPVID.sh
 
  '''harley$''' sudo chmod 744 /etc/systemd/network/DefaultPVID.sh
 
  '''harley$'''
 
  '''harley$'''
Test with <code>'''harley$''' sudo /etc/systemd/network/DefaultPVID.sh</code>. Next I create a service to execute this script:
+
Next I create a service to execute this script:
 
  '''harley$''' cat /etc/systemd/system/DefaultPVID.service  
 
  '''harley$''' cat /etc/systemd/system/DefaultPVID.service  
 
  [Unit]
 
  [Unit]
Zeile 422: Zeile 421:
 
  WantedBy=multi-user.target
 
  WantedBy=multi-user.target
 
  '''harley$'''
 
  '''harley$'''
Test with <code>'''harley$''' sudo systemctl start DefaultPVID.service && systemctl status DefaultPVID.service</code>. After this I create a [https://www.freedesktop.org/software/systemd/man/systemd.unit.html#id-1.11.3 drop-in file for overriding vendor settings] so this service will be executed together with <code>systemd-networkd</code>:
+
And then I create a [https://www.freedesktop.org/software/systemd/man/systemd.unit.html#id-1.11.3 drop-in file for overriding vendor settings] so this service will be executed together with <code>systemd-networkd</code>:
 
  '''harley$''' cat /etc/systemd/system/systemd-networkd.service.d/DefaultPVID.conf  
 
  '''harley$''' cat /etc/systemd/system/systemd-networkd.service.d/DefaultPVID.conf  
 
  [Unit]
 
  [Unit]
Zeile 430: Zeile 429:
 
  Before=DefaultPVID.service
 
  Before=DefaultPVID.service
 
  '''harley$'''
 
  '''harley$'''
Test with <code>'''harley$''' sudo systemctl restart systemd-networkd</code>.
 
  
 
[[Category:Virtualization]]
 
[[Category:Virtualization]]

Bitte beachte, dass alle Beiträge zu Ingos Wiki von anderen Mitwirkenden bearbeitet, geändert oder gelöscht werden können. Reiche hier keine Texte ein, falls du nicht willst, dass diese ohne Einschränkung geändert werden können.

Du bestätigst hiermit auch, dass du diese Texte selbst geschrieben hast oder diese von einer gemeinfreien Quelle kopiert hast (weitere Einzelheiten unter My wiki:Urheberrechte). ÜBERTRAGE OHNE GENEHMIGUNG KEINE URHEBERRECHTLICH GESCHÜTZTEN INHALTE!

Abbrechen | Bearbeitungshilfe (wird in einem neuen Fenster geöffnet)