Segmentare la rete con VLAN 802.1Q
Le VLAN permettono di isolare il traffico di rete su uno stesso switch fisico. Utile per separare homelab, IoT, ospiti e gestione.
1. Concetti base
- VLAN ID: numero 1-4094 che identifica la rete virtuale
- Trunk: porta che trasporta traffico di più VLAN (tagged)
- Access: porta assegnata a una singola VLAN (untagged)
2. Schema tipico homelab
VLAN 10 - Management (switch, Proxmox, IPMI)
VLAN 20 - Servers (VM, container, servizi)
VLAN 30 - Client (PC, laptop, telefoni)
VLAN 40 - IoT (dispositivi smart, telecamere)
VLAN 50 - Guest (WiFi ospiti, isolata)
3. Configurare VLAN su Linux
# Installare vlan support
apt install vlan -y
modprobe 8021q
# Creare interfaccia VLAN
ip link add link eth0 name eth0.20 type vlan id 20
ip addr add 192.168.20.1/24 dev eth0.20
ip link set eth0.20 up
4. Persistente con Netplan
network:
ethernets:
eth0:
dhcp4: no
vlans:
vlan20:
id: 20
link: eth0
addresses: [192.168.20.1/24]
5. Routing tra VLAN
# Abilitare IP forwarding
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
# Regole firewall tra VLAN
iptables -A FORWARD -i eth0.20 -o eth0.30 -j ACCEPT
iptables -A FORWARD -i eth0.30 -o eth0.20 -m state --state ESTABLISHED,RELATED -j ACCEPT
Le VLAN sono fondamentali per la sicurezza: isolano il traffico e limitano la superficie di attacco in caso di compromissione di un segmento.