Linux Layer 2 VLAN Switch: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(8 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 5: Zeile 5:
 
* Ein Layer 2 Switch soll die Netze für Admin und LAN trennen
 
* Ein Layer 2 Switch soll die Netze für Admin und LAN trennen
 
* Die Firewall soll beide Netze routen
 
* Die Firewall soll beide Netze routen
 +
* Als Beispiel wurde für das Admin-Netzwerk 192.168.0.0/24 und für das LAN 192.168.178.0/24 gewählt
 +
== physischer Netzwerkplan ==
 
{{#drawio:linux-layer2-switch-01}}
 
{{#drawio:linux-layer2-switch-01}}
 +
 +
== logischer Netzwerkplan ==
 +
{{#drawio:linux-layer2-switch-02}}
  
 
= Konfiguration der Firewall =
 
= Konfiguration der Firewall =
 +
* '''apt install vlan'''
 +
* Auf der Schnittstelle zum Switch werden zwei virtuelle Schnittellen mit den jeweiligen VLANs konfiguriert
 +
* Die IP-Adressen der VLANs sollten die Gateways der jeweiligen Netzwerke sein
 +
*'''vim ''/etc/network/interfaces'' '''
 +
...
 +
auto enp0s8
 +
iface enp0s8 inet manual
 +
 +
auto enp0s8.1
 +
iface enp0s8.1 inet static
 +
  address 192.168.0.1/24
 +
 +
auto enp0s8.2
 +
iface enp0s8.2 inet static
 +
  address 192.168.168.1/24
 +
 
= Konfiguration des Switches =
 
= Konfiguration des Switches =
 +
* Für virtualiserte Maschinen sollten die Schnittstellen auf ''promiscuous'' gestellt sein, damit sie alle Pakete annehmen
 +
* '''apt install bridge-utils vlan'''
 +
* Die VLANs können direkt an der Bridge eingestellt werden
 
*  
 
*  
 
* '''vim ''/etc/network/interfaces'' '''
 
* '''vim ''/etc/network/interfaces'' '''
  auto lo
+
  ...
iface lo inet loopback
 
 
# The primary network interface
 
 
  auto enp0s3
 
  auto enp0s3
 
  iface enp0s3 inet manual
 
  iface enp0s3 inet manual
 
auto enp0s3.1
 
iface enp0s3.1 inet manual
 
 
auto enp0s3.2
 
iface enp0s3.2 inet manual
 
 
   
 
   
 
  auto enp0s8
 
  auto enp0s8
 
  iface enp0s8 inet manual
 
  iface enp0s8 inet manual
 
auto enp0s8.1
 
iface enp0s8.1 inet manual
 
 
   
 
   
 
  auto enp0s9
 
  auto enp0s9
 
  iface enp0s9 inet manual
 
  iface enp0s9 inet manual
 
auto enp0s9.2
 
iface enp0s9.2 inet manual
 
 
auto enp0s10.2
 
iface enp0s10.2 inet manual
 
 
   
 
   
 
  auto br0
 
  auto br0
 
  iface br0 inet static
 
  iface br0 inet static
   address 172.16.100.2/24
+
   address 192.168.0.2/24
   gateway 172.16.100.1
+
   gateway 192.168.0.1
 
   bridge_vlan_aware yes
 
   bridge_vlan_aware yes
 
   bridge_ports all
 
   bridge_ports all
 +
  post-up bridge vlan add dev enp0s3 vid 1-2
 +
  post-up bridge vlan add dev enp0s9 vid 2 pvid untagged
 +
  post-up bridge vlan add dev enp0s10 vid 2 pvid untagged
 
   post-up bridge vlan delete dev enp0s9 vid 1
 
   post-up bridge vlan delete dev enp0s9 vid 1
 
   post-up bridge vlan delete dev enp0s10 vid 1
 
   post-up bridge vlan delete dev enp0s10 vid 1
  post-up bridge vlan delete dev enp0s3.2 vid 1
 
  post-up bridge vlan delete dev enp0s9.2 vid 1
 
  post-up bridge vlan delete dev enp0s10.2 vid 1
 
  post-up bridge vlan add dev enp0s3 vid 1-2 untagged
 
  post-up bridge vlan add dev enp0s9 vid 2 pvid untagged
 
  post-up bridge vlan add dev enp0s10 vid 2 pvid untagged
 
  post-up bridge vlan add dev enp0s3.2 vid 2 pvid untagged
 
  post-up bridge vlan add dev enp0s9.2 vid 2 pvid untagged
 
  post-up bridge vlan add dev enp0s10.2 vid 2 pvid untagged
 
  
 
* '''reboot'''
 
* '''reboot'''
 
* Die VLAN Konfiguration kann sollten dann so aussehen
 
* Die VLAN Konfiguration kann sollten dann so aussehen
* '''cat ''/proc/net/vlan/config'' '''
+
* '''ip -d -j -p l show br0 | grep "vlan_filtering"'''
 
+
  "vlan_filtering": 1,
  VLAN Dev name    | VLAN ID
 
Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
 
enp0s3.1      | 1  | enp0s3
 
enp0s3.2      | 2  | enp0s3
 
enp0s8.1       | 1  | enp0s8
 
enp0s9.2      | 2  | enp0s9
 
enp0s10.2      | 2  | enp0s10
 
 
 
 
* '''bridge vlan'''
 
* '''bridge vlan'''
  
 
  port              vlan-id
 
  port              vlan-id
  enp0s3            1 Egress Untagged
+
  enp0s3            1
                   2 Egress Untagged
+
                   2
 
  enp0s8            1 PVID Egress Untagged
 
  enp0s8            1 PVID Egress Untagged
 
  enp0s9            2 PVID Egress Untagged
 
  enp0s9            2 PVID Egress Untagged
 
  enp0s10          2 PVID Egress Untagged
 
  enp0s10          2 PVID Egress Untagged
enp0s3.1          1 PVID Egress Untagged
 
enp0s3.2          2 PVID Egress Untagged
 
enp0s8.1          1 PVID Egress Untagged
 
enp0s9.2          2 PVID Egress Untagged
 
enp0s10.2        2 PVID Egress Untagged
 
 
  br0              1 PVID Egress Untagged
 
  br0              1 PVID Egress Untagged

Aktuelle Version vom 16. September 2024, 23:04 Uhr

Ziel

  • Ein Layer 2 Switch soll die Netze für Admin und LAN trennen
  • Die Firewall soll beide Netze routen
  • Als Beispiel wurde für das Admin-Netzwerk 192.168.0.0/24 und für das LAN 192.168.178.0/24 gewählt

physischer Netzwerkplan

logischer Netzwerkplan

Konfiguration der Firewall

  • apt install vlan
  • Auf der Schnittstelle zum Switch werden zwei virtuelle Schnittellen mit den jeweiligen VLANs konfiguriert
  • Die IP-Adressen der VLANs sollten die Gateways der jeweiligen Netzwerke sein
  • vim /etc/network/interfaces
...
auto enp0s8
iface enp0s8 inet manual

auto enp0s8.1
iface enp0s8.1 inet static
 address 192.168.0.1/24

auto enp0s8.2
iface enp0s8.2 inet static
 address 192.168.168.1/24

Konfiguration des Switches

  • Für virtualiserte Maschinen sollten die Schnittstellen auf promiscuous gestellt sein, damit sie alle Pakete annehmen
  • apt install bridge-utils vlan
  • Die VLANs können direkt an der Bridge eingestellt werden
  • vim /etc/network/interfaces
...
auto enp0s3
iface enp0s3 inet manual

auto enp0s8
iface enp0s8 inet manual

auto enp0s9
iface enp0s9 inet manual

auto br0
iface br0 inet static
 address 192.168.0.2/24
 gateway 192.168.0.1
 bridge_vlan_aware yes
 bridge_ports all
 post-up bridge vlan add dev enp0s3 vid 1-2
 post-up bridge vlan add dev enp0s9 vid 2 pvid untagged
 post-up bridge vlan add dev enp0s10 vid 2 pvid untagged
 post-up bridge vlan delete dev enp0s9 vid 1
 post-up bridge vlan delete dev enp0s10 vid 1
  • reboot
  • Die VLAN Konfiguration kann sollten dann so aussehen
  • ip -d -j -p l show br0 | grep "vlan_filtering"
"vlan_filtering": 1,
  • bridge vlan
port              vlan-id
enp0s3            1
                  2
enp0s8            1 PVID Egress Untagged
enp0s9            2 PVID Egress Untagged
enp0s10           2 PVID Egress Untagged
br0               1 PVID Egress Untagged