Open Vswitch Projekt: Unterschied zwischen den Versionen
| Zeile 1: | Zeile 1: | ||
| − | = Open vSwitch (OVS) als Cisco-ähnlicher L2-Switch mit Management-IP = | + | == Open vSwitch (OVS) als Cisco-ähnlicher L2-Switch mit Management-IP == |
== Ziel == | == Ziel == | ||
| Zeile 13: | Zeile 13: | ||
== Voraussetzungen == | == Voraussetzungen == | ||
| − | * Debian 12 | + | * Debian 12 |
* Linux-VM mit ≥ 18 Netzwerkkarten (eth0–eth17) | * Linux-VM mit ≥ 18 Netzwerkkarten (eth0–eth17) | ||
* Root-Zugriff | * Root-Zugriff | ||
| Zeile 19: | Zeile 19: | ||
== Installation == | == Installation == | ||
| − | + | <pre> | |
| − | + | apt update | |
| + | apt install openvswitch-switch snmpd network-manager | ||
| + | </pre> | ||
| + | |||
| + | NetworkManager als Standard-Renderer aktivieren: | ||
| + | <pre> | ||
| + | systemctl enable --now NetworkManager | ||
| + | </pre> | ||
| + | |||
| + | == Interfaces per nmcli hochziehen == | ||
| + | |||
| + | Die physischen Interfaces werden ausschließlich per '''nmcli''' aktiviert — kein Editieren von Konfigurationsdateien nötig. | ||
| + | OVS übernimmt danach die komplette VLAN- und Bridge-Konfiguration. | ||
| + | |||
| + | Für jedes Interface (eth0–eth16) ein Connection-Profil anlegen und aktivieren: | ||
| + | <pre> | ||
| + | for i in $(seq 0 16); do | ||
| + | nmcli con add type ethernet ifname eth$i con-name eth$i \ | ||
| + | ipv4.method disabled \ | ||
| + | ipv6.method ignore \ | ||
| + | connection.autoconnect yes | ||
| + | nmcli con up eth$i | ||
| + | done | ||
| + | </pre> | ||
| + | |||
| + | Separater Uplink eth17 mit DHCP: | ||
| + | <pre> | ||
| + | nmcli con add type ethernet ifname eth17 con-name eth17 \ | ||
| + | ipv4.method auto \ | ||
| + | connection.autoconnect yes | ||
| + | nmcli con up eth17 | ||
| + | </pre> | ||
== OVS-Bridge anlegen == | == OVS-Bridge anlegen == | ||
| − | + | <pre> | |
| + | ovs-vsctl add-br sw0 | ||
| + | </pre> | ||
| − | == Trunk-Port konfigurieren (OPNsense) == | + | == Trunk-Port konfigurieren (z. B. Richtung OPNsense/Router) == |
| − | + | <pre> | |
| + | ovs-vsctl add-port sw0 eth0 tag=1 trunks=21,22,23 vlan_mode=native-untagged | ||
| + | </pre> | ||
== Access-Ports konfigurieren == | == Access-Ports konfigurieren == | ||
| − | + | <pre> | |
| − | + | ovs-vsctl add-port sw0 eth1 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth2 tag=21 | |
| − | + | ovs-vsctl add-port sw0 eth3 tag=22 | |
| − | + | ovs-vsctl add-port sw0 eth4 tag=23 | |
| − | + | ovs-vsctl add-port sw0 eth5 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth6 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth7 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth8 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth9 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth10 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth11 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth12 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth13 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth14 tag=1 | |
| − | + | ovs-vsctl add-port sw0 eth15 tag=1 | |
| + | ovs-vsctl add-port sw0 eth16 tag=1 | ||
| + | </pre> | ||
== Management-Interface im VLAN 1 == | == Management-Interface im VLAN 1 == | ||
| − | |||
| − | + | Internen OVS-Port für die Management-IP anlegen: | |
<pre> | <pre> | ||
| − | + | ovs-vsctl add-port sw0 mgmt tag=1 -- set interface mgmt type=internal | |
| − | + | </pre> | |
| − | + | Management-IP per nmcli setzen: | |
| − | + | <pre> | |
| − | + | nmcli con add type ethernet ifname mgmt con-name mgmt \ | |
| − | + | ipv4.method manual \ | |
| − | + | ipv4.addresses 172.26.56.2/26 \ | |
| − | + | ipv4.gateway 172.26.56.1 \ | |
| − | + | connection.autoconnect yes | |
| − | + | nmcli con up mgmt | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | gateway 172.26.56.1 | ||
</pre> | </pre> | ||
| − | + | == Mirror-Port konfigurieren (SPAN) == | |
<pre> | <pre> | ||
ovs-vsctl -- --id=@m create Mirror name=mirror0 \ | ovs-vsctl -- --id=@m create Mirror name=mirror0 \ | ||
select-vlan=1,21,22,23 \ | select-vlan=1,21,22,23 \ | ||
output-port=eth17 \ | output-port=eth17 \ | ||
| − | -- set Bridge | + | -- set Bridge sw0 mirrors=@m |
</pre> | </pre> | ||
| Zeile 120: | Zeile 119: | ||
=== Nutzung === | === Nutzung === | ||
| − | * An ''eth17'' wird ein IDS oder ein Analyse-System (z. B. Wireshark/tcpdump) angeschlossen | + | * An '''eth17''' wird ein IDS oder ein Analyse-System (z. B. Wireshark/tcpdump) angeschlossen |
* Dort ist der gesamte Traffic der VLANs 1, 21, 22 und 23 sichtbar | * Dort ist der gesamte Traffic der VLANs 1, 21, 22 und 23 sichtbar | ||
| Zeile 131: | Zeile 130: | ||
SNMP-Dienst neu starten: | SNMP-Dienst neu starten: | ||
| − | + | <pre> | |
| + | systemctl restart snmpd | ||
| + | </pre> | ||
Test der SNMPv3-Abfrage: | Test der SNMPv3-Abfrage: | ||
| − | + | <pre> | |
| + | snmpwalk -v3 -u ovsuser -l authPriv -a SHA -A MeinGeheimesPasswort -x AES -X NochGeheimer localhost ifDescr | ||
| + | </pre> | ||
== Wichtige Befehle == | == Wichtige Befehle == | ||
| − | Zeigt die komplette OVS-Bridge-Konfiguration (Bridges, Ports, VLAN-Tags). | + | |
| + | === OVS-Diagnose === | ||
| + | |||
| + | Zeigt die komplette OVS-Bridge-Konfiguration (Bridges, Ports, VLAN-Tags). | ||
* '''ovs-vsctl show''' | * '''ovs-vsctl show''' | ||
| − | Listet alle Ports, die an der Bridge '' | + | Listet alle Ports, die an der Bridge ''sw0'' hängen. |
| − | * '''ovs-vsctl list-ports | + | * '''ovs-vsctl list-ports sw0''' |
| − | Zeigt Details zum Port ''eth1'' (inklusive VLAN-Tag). | + | Zeigt Details zum Port ''eth1'' (inklusive VLAN-Tag). |
* '''ovs-vsctl list interface eth1''' | * '''ovs-vsctl list interface eth1''' | ||
| − | Zeigt, welche VLANs auf dem Trunk-Port ''eth0'' erlaubt sind. | + | Zeigt, welche VLANs auf dem Trunk-Port ''eth0'' erlaubt sind. |
* '''ovs-vsctl get port eth0 trunks''' | * '''ovs-vsctl get port eth0 trunks''' | ||
| − | Zeigt den Zustand der Datenebene (DPIF-Interfaces, OpenFlow). | + | Zeigt den Zustand der Datenebene (DPIF-Interfaces, OpenFlow). |
* '''ovs-dpctl show''' | * '''ovs-dpctl show''' | ||
| − | Zeigt die Forwarding Database (FDB), ähnlich wie | + | Zeigt die Forwarding Database (FDB), ähnlich wie ''show mac address-table'' auf Cisco. |
| − | * '''ovs-appctl fdb/show | + | * '''ovs-appctl fdb/show sw0''' |
| + | |||
| + | Zeigt vorhandene SPAN/Mirror-Konfigurationen. | ||
| + | * '''ovs-appctl mirror/list sw0''' | ||
| + | |||
| + | === nmcli-Diagnose === | ||
| + | |||
| + | Zeigt alle aktiven Verbindungen. | ||
| + | * '''nmcli con show --active''' | ||
| − | Zeigt | + | Zeigt den Status eines bestimmten Interface. |
| − | * ''' | + | * '''nmcli dev status''' |
=== VLAN-Konfiguration ändern === | === VLAN-Konfiguration ändern === | ||
| − | Setzt ''eth1'' als Access-Port im VLAN 10 (untagged). | + | |
| + | Setzt ''eth1'' als Access-Port im VLAN 10 (untagged). | ||
* '''ovs-vsctl set port eth1 tag=10''' | * '''ovs-vsctl set port eth1 tag=10''' | ||
| − | Setzt ''eth2'' als Trunk-Port für VLAN 10, 20 und 30 (getagged). | + | Setzt ''eth2'' als Trunk-Port für VLAN 10, 20 und 30 (getagged). |
* '''ovs-vsctl set port eth2 trunks=10,20,30''' | * '''ovs-vsctl set port eth2 trunks=10,20,30''' | ||
| − | Setzt ''eth2'' als Trunk-Port, VLAN 10 untagged (native), VLAN 20 und 30 getagged. | + | Setzt ''eth2'' als Trunk-Port, VLAN 10 untagged (native), VLAN 20 und 30 getagged. |
* '''ovs-vsctl set port eth2 tag=10 trunks=20,30''' | * '''ovs-vsctl set port eth2 tag=10 trunks=20,30''' | ||
| − | Entfernt VLAN-Zuweisung von ''eth1'' bzw. VLAN 20 von ''eth2''. | + | Entfernt VLAN-Zuweisung von ''eth1'' bzw. VLAN 20 von ''eth2''. |
| − | * '''ovs-vsctl remove port eth1 tag''' | + | * '''ovs-vsctl remove port eth1 tag''' |
* '''ovs-vsctl remove port eth2 trunks 20''' | * '''ovs-vsctl remove port eth2 trunks 20''' | ||
== Ergebnis == | == Ergebnis == | ||
* '''eth0''' = Trunk (VLAN 1 native untagged, VLAN 21/22/23 getaggt) | * '''eth0''' = Trunk (VLAN 1 native untagged, VLAN 21/22/23 getaggt) | ||
| − | * '''eth1–eth16''' = Access-Ports (je VLAN, untagged) | + | * '''eth1–eth16''' = Access-Ports (je VLAN, untagged) — 14 für VMs, 2 Reserve |
| − | * ''' | + | * '''eth17''' = Mirror/SPAN-Ausgang + DHCP-Uplink |
* '''mgmt''' = Management-Port im VLAN 1 mit IP 172.26.56.2/26 | * '''mgmt''' = Management-Port im VLAN 1 mit IP 172.26.56.2/26 | ||
| − | |||
* '''SNMPv3''' = Überwachung aller Interfaces möglich | * '''SNMPv3''' = Überwachung aller Interfaces möglich | ||
| + | * Kein Editieren von Konfigurationsdateien nötig | ||
== Nächste Schritte == | == Nächste Schritte == | ||
Version vom 2. Mai 2026, 07:30 Uhr
Open vSwitch (OVS) als Cisco-ähnlicher L2-Switch mit Management-IP
Ziel
In diesem Artikel wird beschrieben, wie man unter Linux mit Open vSwitch (OVS) eine Schulungsumgebung aufbaut, die einem Cisco Catalyst oder Nexus Switch ähnelt. Funktionen im ersten Schritt:
- bis zu 18 Interfaces (eth0–eth17)
- VLANs (1, 21, 22, 23)
- 1 Trunk-Port mit VLAN 1 (native untagged) + VLANs 21/22/23 getaggt
- mehrere Access-Ports (je ein VLAN)
- 1 Mirror-Port (SPAN)
- SNMPv3 zur Überwachung
- Management-IP im VLAN 1
Voraussetzungen
- Debian 12
- Linux-VM mit ≥ 18 Netzwerkkarten (eth0–eth17)
- Root-Zugriff
- In VirtualBox/KVM: alle NICs auf Promiscuous Mode: Allow All
Installation
apt update apt install openvswitch-switch snmpd network-manager
NetworkManager als Standard-Renderer aktivieren:
systemctl enable --now NetworkManager
Interfaces per nmcli hochziehen
Die physischen Interfaces werden ausschließlich per nmcli aktiviert — kein Editieren von Konfigurationsdateien nötig. OVS übernimmt danach die komplette VLAN- und Bridge-Konfiguration.
Für jedes Interface (eth0–eth16) ein Connection-Profil anlegen und aktivieren:
for i in $(seq 0 16); do
nmcli con add type ethernet ifname eth$i con-name eth$i \
ipv4.method disabled \
ipv6.method ignore \
connection.autoconnect yes
nmcli con up eth$i
done
Separater Uplink eth17 mit DHCP:
nmcli con add type ethernet ifname eth17 con-name eth17 \
ipv4.method auto \
connection.autoconnect yes
nmcli con up eth17
OVS-Bridge anlegen
ovs-vsctl add-br sw0
Trunk-Port konfigurieren (z. B. Richtung OPNsense/Router)
ovs-vsctl add-port sw0 eth0 tag=1 trunks=21,22,23 vlan_mode=native-untagged
Access-Ports konfigurieren
ovs-vsctl add-port sw0 eth1 tag=1 ovs-vsctl add-port sw0 eth2 tag=21 ovs-vsctl add-port sw0 eth3 tag=22 ovs-vsctl add-port sw0 eth4 tag=23 ovs-vsctl add-port sw0 eth5 tag=1 ovs-vsctl add-port sw0 eth6 tag=1 ovs-vsctl add-port sw0 eth7 tag=1 ovs-vsctl add-port sw0 eth8 tag=1 ovs-vsctl add-port sw0 eth9 tag=1 ovs-vsctl add-port sw0 eth10 tag=1 ovs-vsctl add-port sw0 eth11 tag=1 ovs-vsctl add-port sw0 eth12 tag=1 ovs-vsctl add-port sw0 eth13 tag=1 ovs-vsctl add-port sw0 eth14 tag=1 ovs-vsctl add-port sw0 eth15 tag=1 ovs-vsctl add-port sw0 eth16 tag=1
Management-Interface im VLAN 1
Internen OVS-Port für die Management-IP anlegen:
ovs-vsctl add-port sw0 mgmt tag=1 -- set interface mgmt type=internal
Management-IP per nmcli setzen:
nmcli con add type ethernet ifname mgmt con-name mgmt \
ipv4.method manual \
ipv4.addresses 172.26.56.2/26 \
ipv4.gateway 172.26.56.1 \
connection.autoconnect yes
nmcli con up mgmt
Mirror-Port konfigurieren (SPAN)
ovs-vsctl -- --id=@m create Mirror name=mirror0 \
select-vlan=1,21,22,23 \
output-port=eth17 \
-- set Bridge sw0 mirrors=@m
Kontrolle
ovs-vsctl list Mirror
Erwartete Ausgabe (gekürzt):
- name: mirror0
- select-vlan: [1,21,22,23]
- output-port: eth17
Nutzung
- An eth17 wird ein IDS oder ein Analyse-System (z. B. Wireshark/tcpdump) angeschlossen
- Dort ist der gesamte Traffic der VLANs 1, 21, 22 und 23 sichtbar
SNMPv3 konfigurieren
Datei /etc/snmp/snmpd.conf anpassen:
createUser ovsuser SHA "MeinGeheimesPasswort" AES "NochGeheimer" rouser ovsuser authPriv
SNMP-Dienst neu starten:
systemctl restart snmpd
Test der SNMPv3-Abfrage:
snmpwalk -v3 -u ovsuser -l authPriv -a SHA -A MeinGeheimesPasswort -x AES -X NochGeheimer localhost ifDescr
Wichtige Befehle
OVS-Diagnose
Zeigt die komplette OVS-Bridge-Konfiguration (Bridges, Ports, VLAN-Tags).
- ovs-vsctl show
Listet alle Ports, die an der Bridge sw0 hängen.
- ovs-vsctl list-ports sw0
Zeigt Details zum Port eth1 (inklusive VLAN-Tag).
- ovs-vsctl list interface eth1
Zeigt, welche VLANs auf dem Trunk-Port eth0 erlaubt sind.
- ovs-vsctl get port eth0 trunks
Zeigt den Zustand der Datenebene (DPIF-Interfaces, OpenFlow).
- ovs-dpctl show
Zeigt die Forwarding Database (FDB), ähnlich wie show mac address-table auf Cisco.
- ovs-appctl fdb/show sw0
Zeigt vorhandene SPAN/Mirror-Konfigurationen.
- ovs-appctl mirror/list sw0
nmcli-Diagnose
Zeigt alle aktiven Verbindungen.
- nmcli con show --active
Zeigt den Status eines bestimmten Interface.
- nmcli dev status
VLAN-Konfiguration ändern
Setzt eth1 als Access-Port im VLAN 10 (untagged).
- ovs-vsctl set port eth1 tag=10
Setzt eth2 als Trunk-Port für VLAN 10, 20 und 30 (getagged).
- ovs-vsctl set port eth2 trunks=10,20,30
Setzt eth2 als Trunk-Port, VLAN 10 untagged (native), VLAN 20 und 30 getagged.
- ovs-vsctl set port eth2 tag=10 trunks=20,30
Entfernt VLAN-Zuweisung von eth1 bzw. VLAN 20 von eth2.
- ovs-vsctl remove port eth1 tag
- ovs-vsctl remove port eth2 trunks 20
Ergebnis
- eth0 = Trunk (VLAN 1 native untagged, VLAN 21/22/23 getaggt)
- eth1–eth16 = Access-Ports (je VLAN, untagged) — 14 für VMs, 2 Reserve
- eth17 = Mirror/SPAN-Ausgang + DHCP-Uplink
- mgmt = Management-Port im VLAN 1 mit IP 172.26.56.2/26
- SNMPv3 = Überwachung aller Interfaces möglich
- Kein Editieren von Konfigurationsdateien nötig
Nächste Schritte
- Weitere VLANs hinzufügen
- Layer-3 Routing mit OVS oder FRRouting ergänzen
- VXLAN/EVPN mit OVN erproben