PassioniInformaticaLinux

Guida: WireGuard VPN — collegare server remoti alla LAN

22/02/2026

VPN site-to-site con WireGuard

Configurazione di una VPN WireGuard per collegare server remoti (es. cloud OVH) alla rete LAN di casa.

1. Installazione (su entrambi i nodi)

apt install -y wireguard
cd /etc/wireguard
umask 077
wg genkey | tee privatekey | wg pubkey > publickey

2. Configurazione Server (gateway LAN)

cat > /etc/wireguard/wg0.conf <<EOF
[Interface]
Address = 10.66.66.1/24
ListenPort = 51820
PrivateKey = $(cat privatekey)
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

[Peer]
# Client remoto (es. VPS OVH)
PublicKey = CHIAVE_PUBBLICA_CLIENT
AllowedIPs = 10.66.66.5/32
EOF

3. Configurazione Client (server remoto)

cat > /etc/wireguard/wg0.conf <<EOF
[Interface]
Address = 10.66.66.5/24
PrivateKey = $(cat privatekey)
DNS = 1.1.1.1

[Peer]
PublicKey = CHIAVE_PUBBLICA_SERVER
Endpoint = IP-PUBBLICO-CASA:51820
AllowedIPs = 10.66.66.0/24, 192.168.1.0/24
PersistentKeepalive = 25
EOF

4. Avvio e abilitazione

# Su entrambi i nodi
wg-quick up wg0
systemctl enable wg-quick@wg0

5. Verifica

wg show
ping 10.66.66.1   # Dal client
ping 192.168.1.92  # Accesso alla LAN via VPN

6. Firewall

# Sul server
ufw allow 51820/udp
# Abilita IP forwarding
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p

Risultato: Server remoti collegati alla LAN tramite VPN cifrata e performante.

← Guida: Monitoraggio server con Prometheus + Gra... Guida: Docker e Docker Compose — deploy di serv... →
← Torna all'elenco