VLAN mit Linux und Open vSwitch
Version vom 3. Mai 2026, 14:26 Uhr von Thomas.will (Diskussion | Beiträge)
Zielbeschreibung
| Port | VLAN | Modus |
|---|---|---|
| port1 | 1 (native), 21, 22, 23 (tagged) | trunk native-untagged |
| port2 | 21 | access |
| port3 | 21 | access |
| port4 | 21 | access |
| port5 | 21 | access |
| port6 | 21 | access |
| port7 | 21 | access |
| port8 | 21 | access |
| port9 | 21 | access |
| port10 | 22 | access |
| port11 | 22 | access |
| port12 | 22 | access |
| port13 | 22 | access |
| port14 | 23 | access |
| port15 | 23 | access |
| port16 | 23 | access |
- VLAN 1 → 172.27.2XX.0/24 → MGMT
- VLAN 21 → 10.88.2XX.0/24 → DMZ
- VLAN 22 → 172.26.2XX.0/24 → LAN
- VLAN 23 → 10.2XX.1.0/24 → SERVER
Plan
Voraussetzungen auf Debian/Linux
- VLAN-Paket installieren
- apt install vlan
- VLAN-Modul laden
- sudo modprobe 8021q
- Modul beim Booten automatisch laden
- echo 8021q | sudo tee -a /etc/modules
/etc/network/interfaces
#MGMT auto enp0s8 iface enp0s8 inet static address 172.26.56.1/24 #DMZ auto enp0s8.21 iface enp0s8.21 inet static address 10.88.2XX.1/24 vlan-raw-device enp0s8 post-up ip rule add fwmark 0x2 lookup 100 post-up ip route add default via 10.88.2XX.4 table 100 #LAN auto enp0s8.22 iface enp0s8.22 inet static address 172.26.2XX.1/24 vlan-raw-device enp0s8 #SERVER auto enp0s8.23 iface enp0s8.23 inet static address 10.2XX.1.1/24 vlan-raw-device enp0s8
Zum Open vSwitch
- ssh localhost -p 2222
oder im Notfall
- nc localhost 2222
- Logindaten
- user: kit
- pass: kit
- root: mit sudo -i
VLAN zuordnen
- ovs-vsctl add-port sw0 port1 tag=1 trunks=21,22,23 vlan_mode=native-untagged
- ovs-vsctl add-port sw0 port2 tag=21
- ovs-vsctl add-port sw0 port3 tag=21
- ovs-vsctl add-port sw0 port3 tag=21
- ovs-vsctl add-port sw0 port4 tag=21
- ovs-vsctl add-port sw0 port5 tag=21
- ovs-vsctl add-port sw0 port6 tag=21
- ovs-vsctl add-port sw0 port7 tag=21
- ovs-vsctl add-port sw0 port8 tag=21
- ovs-vsctl add-port sw0 port9 tag=21
- ovs-vsctl add-port sw0 port10 tag=22
- ovs-vsctl add-port sw0 port11 tag=22
- ovs-vsctl add-port sw0 port12 tag=22
- ovs-vsctl add-port sw0 port13 tag=22
- ovs-vsctl add-port sw0 port14 tag=23
- ovs-vsctl add-port sw0 port15 tag=23
- ovs-vsctl add-port sw0 port16 tag=23
Vlan Interfaces anlegen
- ovs-vsctl add-port sw0 mgmt tag=1 -- set interface mgmt type=internal*
- ovs-vsctl add-port sw0 dmz tag=21 -- set interface dmz type=internal
- ovs-vsctl add-port sw0 lan tag=22 -- set interface lan type=internal
- ovs-vsctl add-port sw0 server tag=23 -- set interface server type=internal
MGMT IP setzen
- cat >> /etc/network/interfaces << 'EOF'
auto mgmt
iface mgmt inet static
address 172.26.2XX.2/26
gateway 172.26.2XX.1
dns-nameservers 10.88.2XX.21
dns-search it2XX.int
EOF
- ifup mgmt
Mirror-Port konfigurieren (SPAN)
port17 dient als Mirror-Ausgang — dort kann ein IDS oder Wireshark angeschlossen werden:
ovs-vsctl add-port sw0 port17
ovs-vsctl -- --id=@p get port port17 \
-- --id=@m create Mirror name=mirror0 \
select-vlan=1,21,22,23 \
output-port=@p \
-- set Bridge sw0 mirrors=@m
Kontrolle
ovs-vsctl list Mirror
Erwartete Ausgabe (gekürzt):
- name: mirror0
- select-vlan: [1,21,22,23]
- output-port: port17
Nutzung
- An port17 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
TODO Anpassungen
- Firewall
- DHCP Server
- Sonst nochwas?
