Wireguard gibt es ja jetzt schon eine Weile, Zeit also bei meinem kommenden hosted Server die noch recht junge VPN Variante auszuprobieren.
Eine passable Anleitung habe ich hier gefunden:
https://www.server-world.info/en/note?os=Debian_12&p=wireguard&f=1 (Archiv)
Tatsächlich ist – sobald einmal verstanden – das erstellen der private keys und public keys das schwierigste bei wireguard. Der Rest ist Bestandteil des Linux Kernels.
Hier meine Server-Config mit 3 externen Peers:
[Interface]
# specify generated private key for server
PrivateKey = <private key server>
# IP address for VPN interface
Address = 10.0.88.1
# UDP port WireGuard server listens
ListenPort = 51820
# possible to set any commands after WireGuard starts/stops
# set routing rules like follows to access to local network via VPN session
# [wg0] ⇒ VPN interface name
# [eth0] ⇒ Ethernet interface name
PostUp = echo 1 > /proc/sys/net/ipv4/ip_forward; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = echo 0 > /proc/sys/net/ipv4/ip_forward; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
# specify public key pc1
PublicKey = <public key pc1>
AllowedIPs = 10.0.88.5/32
PersistentKeepalive = 25
[Peer]
# specify public key pc2
PublicKey = <public key pc2>
AllowedIPs = 10.0.88.6/32
PersistentKeepalive = 25
[Peer]
# specify public key pc3
PublicKey = <public key pc3>
AllowedIPs = 10.0.88.7/32
PersistentKeepalive = 25
Auf dem ersten Peer sieht es so aus:
[Interface]
PrivateKey = <private key pc1>
Address = 10.0.88.5/32
[Peer]
PublicKey = <public key server>
AllowedIPs = 10.0.88.0/24
Endpoint = 89.58.xxx.xxx:51820
PersistentKeepalive = 25
Tatsächlich musste ich den PersistentKeepalive mit aufnehmen, damit die Verbindung auch bestehen bleibt, damit sich die Peers untereinander anpingen können.
Sobald ich im Client die Allowed IPs auf 10.0.88.1/32 und 0.0.0.0/0 setze, wird der gesamte Internettraffic durch den Wireguard Tunnel geroutet und ich erhalte die externe IP meines gehosteten Servers.
Die Keys sind schnell erstellt mit:wg genkey | tee /etc/wireguard/pc4.key und cat /etc/wireguard/nb-anke.key | wg pubkey | tee /etc/wireguard/pc4.pub