VLAN mit Linux und Open vSwitch: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 34: | Zeile 34: | ||
|- | |- | ||
| port16 || 23 || access | | port16 || 23 || access | ||
| + | |- | ||
| + | | port17 || alle || Mirror (SPAN) | ||
|} | |} | ||
| + | |||
{| class="wikitable" | {| class="wikitable" | ||
! VLAN !! Netz !! Bezeichnung | ! VLAN !! Netz !! Bezeichnung | ||
| Zeile 49: | Zeile 52: | ||
== Plan == | == Plan == | ||
{{#drawio:vlan-linux-cisco}} | {{#drawio:vlan-linux-cisco}} | ||
| − | |||
=== Voraussetzungen auf Debian/Linux === | === Voraussetzungen auf Debian/Linux === | ||
;VLAN-Paket installieren: | ;VLAN-Paket installieren: | ||
| − | + | apt install vlan | |
;VLAN-Modul laden: | ;VLAN-Modul laden: | ||
| − | + | modprobe 8021q | |
;Modul beim Booten automatisch laden: | ;Modul beim Booten automatisch laden: | ||
| − | + | echo 8021q | tee -a /etc/modules | |
| + | |||
=== /etc/network/interfaces === | === /etc/network/interfaces === | ||
| − | < | + | <syntaxhighlight lang="text"> |
| − | + | # MGMT | |
| − | #MGMT | ||
auto enp0s8 | auto enp0s8 | ||
iface enp0s8 inet static | iface enp0s8 inet static | ||
| − | + | address 172.27.2XX.1/24 | |
| − | |||
| − | #DMZ | + | # DMZ |
auto enp0s8.21 | auto enp0s8.21 | ||
iface enp0s8.21 inet static | 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 | + | # LAN |
auto enp0s8.22 | auto enp0s8.22 | ||
iface enp0s8.22 inet static | iface enp0s8.22 inet static | ||
| − | + | address 172.26.2XX.1/24 | |
| − | + | vlan-raw-device enp0s8 | |
| − | |||
| − | #SERVER | + | # SERVER |
auto enp0s8.23 | auto enp0s8.23 | ||
iface enp0s8.23 inet static | iface enp0s8.23 inet static | ||
| − | + | address 10.2XX.1.1/24 | |
| − | + | vlan-raw-device enp0s8 | |
| + | </syntaxhighlight> | ||
| − | + | == Zum Open vSwitch == | |
| + | ssh localhost -p 2222 | ||
| − | |||
| − | |||
oder im Notfall | oder im Notfall | ||
| − | + | nc localhost 2222 | |
| + | |||
;Logindaten | ;Logindaten | ||
*user: kit | *user: kit | ||
| Zeile 99: | Zeile 100: | ||
*root: mit '''sudo -i''' | *root: mit '''sudo -i''' | ||
| − | ===VLAN zuordnen=== | + | === VLAN zuordnen === |
| − | + | ;Trunk | |
| − | + | ovs-vsctl set port port1 tag=1 trunks=21,22,23 vlan_mode=native-untagged | |
| − | + | ;DMZ (VLAN 21) | |
| − | + | ovs-vsctl set port port2 tag=21 | |
| − | + | ovs-vsctl set port port3 tag=21 | |
| − | + | ovs-vsctl set port port4 tag=21 | |
| − | + | ovs-vsctl set port port5 tag=21 | |
| − | + | ovs-vsctl set port port6 tag=21 | |
| − | + | ovs-vsctl set port port7 tag=21 | |
| − | + | ovs-vsctl set port port8 tag=21 | |
| − | + | ovs-vsctl set port port9 tag=21 | |
| − | + | ;LAN (VLAN 22) | |
| − | + | ovs-vsctl set port port10 tag=22 | |
| − | + | ovs-vsctl set port port11 tag=22 | |
| − | + | ovs-vsctl set port port12 tag=22 | |
| − | + | ovs-vsctl set port port13 tag=22 | |
| − | + | ;SERVER (VLAN 23) | |
| + | ovs-vsctl set port port14 tag=23 | ||
| + | ovs-vsctl set port port15 tag=23 | ||
| + | ovs-vsctl set port 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 === | + | === MGMT-IP setzen === |
| − | + | <syntaxhighlight lang="bash"> | |
| − | + | cat >> /etc/network/interfaces << 'EOF' | |
| − | + | auto mgmt | |
| − | + | iface mgmt inet static | |
| − | + | address 172.27.2XX.2/24 | |
| − | + | gateway 172.27.2XX.1 | |
| − | + | dns-nameservers 10.88.2XX.21 | |
| − | + | dns-search it2XX.int | |
| − | + | EOF | |
| − | + | ifup mgmt | |
| + | </syntaxhighlight> | ||
== Mirror-Port konfigurieren (SPAN) == | == Mirror-Port konfigurieren (SPAN) == | ||
port17 dient als Mirror-Ausgang — dort kann ein IDS oder Wireshark angeschlossen werden: | port17 dient als Mirror-Ausgang — dort kann ein IDS oder Wireshark angeschlossen werden: | ||
| − | < | + | <syntaxhighlight lang="bash"> |
| − | |||
ovs-vsctl -- --id=@p get port port17 \ | ovs-vsctl -- --id=@p get port port17 \ | ||
-- --id=@m create Mirror name=mirror0 \ | -- --id=@m create Mirror name=mirror0 \ | ||
| Zeile 145: | Zeile 149: | ||
output-port=@p \ | output-port=@p \ | ||
-- set Bridge sw0 mirrors=@m | -- set Bridge sw0 mirrors=@m | ||
| − | </ | + | </syntaxhighlight> |
=== Kontrolle === | === Kontrolle === | ||
| − | + | ovs-vsctl list Mirror | |
| − | ovs-vsctl list Mirror | ||
| − | |||
Erwartete Ausgabe (gekürzt): | Erwartete Ausgabe (gekürzt): | ||
| − | * name: mirror0 | + | *name: mirror0 |
| − | * select-vlan: [1,21,22,23] | + | *select-vlan: [1,21,22,23] |
| − | * output-port: port17 | + | *output-port: port17 |
=== Nutzung === | === Nutzung === | ||
| − | * An '''port17''' wird ein IDS oder ein Analyse-System (z. B. Wireshark/tcpdump) angeschlossen | + | *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 | + | *Dort ist der gesamte Traffic der VLANs 1, 21, 22 und 23 sichtbar |
| + | |||
| + | == Aktivierung auf dem Linux-Host == | ||
| + | systemctl restart networking | ||
| + | ip addr show | ||
| − | + | == TODO == | |
*Firewall | *Firewall | ||
| − | *DHCP Server | + | *DHCP-Server |
| − | |||
Version vom 3. Mai 2026, 14:32 Uhr
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 |
| port17 | alle | Mirror (SPAN) |
| VLAN | Netz | Bezeichnung |
|---|---|---|
| 1 | 172.27.2XX.0/24 | MGMT |
| 21 | 10.88.2XX.0/24 | DMZ |
| 22 | 172.26.2XX.0/24 | LAN |
| 23 | 10.2XX.1.0/24 | SERVER |
Plan
Voraussetzungen auf Debian/Linux
- VLAN-Paket installieren
apt install vlan
- VLAN-Modul laden
modprobe 8021q
- Modul beim Booten automatisch laden
echo 8021q | tee -a /etc/modules
/etc/network/interfaces
# MGMT
auto enp0s8
iface enp0s8 inet static
address 172.27.2XX.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
- Trunk
ovs-vsctl set port port1 tag=1 trunks=21,22,23 vlan_mode=native-untagged
- DMZ (VLAN 21)
ovs-vsctl set port port2 tag=21 ovs-vsctl set port port3 tag=21 ovs-vsctl set port port4 tag=21 ovs-vsctl set port port5 tag=21 ovs-vsctl set port port6 tag=21 ovs-vsctl set port port7 tag=21 ovs-vsctl set port port8 tag=21 ovs-vsctl set port port9 tag=21
- LAN (VLAN 22)
ovs-vsctl set port port10 tag=22 ovs-vsctl set port port11 tag=22 ovs-vsctl set port port12 tag=22 ovs-vsctl set port port13 tag=22
- SERVER (VLAN 23)
ovs-vsctl set port port14 tag=23 ovs-vsctl set port port15 tag=23 ovs-vsctl set port 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.27.2XX.2/24
gateway 172.27.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 -- --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
Aktivierung auf dem Linux-Host
systemctl restart networking ip addr show
TODO
- Firewall
- DHCP-Server
