Differences
This shows you the differences between two versions of the page.
| computer:network:pihole [2022/10/25 09:59] – angelegt springm | computer:network:pihole [2022/10/25 10:09] (current) – [Wireguard] springm | ||
|---|---|---|---|
| Line 24: | Line 24: | ||
| ====== DynDNS-Script ====== | ====== DynDNS-Script ====== | ||
| - | ====== | + | ====== |
| https:// | https:// | ||
| + | |||
| + | |||
| + | ===== Aufbau und Setup ===== | ||
| + | |||
| + | Raspberry Pi 3 mit Raspbian Buster Lite | ||
| + | der Pi hängt im LAN hinter dem Hauptrouter | ||
| + | LAN: 192.168.150.0/ | ||
| + | VPN Netz: 10.10.10.0/ | ||
| + | Clients als Road Warrior (Android Smartphone und Windows 10 Notebook) | ||
| + | |||
| + | ===== Installation ===== | ||
| + | |||
| + | WireGuard auf dem Raspberry Pi installieren. (Zur Vereinfachung alles als root.) | ||
| + | |||
| + | Raspbian Stretch | ||
| + | $ apt-get update | ||
| + | $ apt-get upgrade | ||
| + | $ apt-get install raspberrypi-kernel-headers | ||
| + | $ echo "deb http:// | ||
| + | $ apt-get install dirmngr | ||
| + | $ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553 | ||
| + | $ printf ' | ||
| + | $ apt-get update | ||
| + | $ apt-get install wireguard | ||
| + | $ reboot | ||
| + | |||
| + | Raspbian Buster (07.07.2019) | ||
| + | $ apt-get update | ||
| + | $ apt-get upgrade | ||
| + | $ apt-get install raspberrypi-kernel-headers | ||
| + | $ echo "deb http:// | ||
| + | $ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC | ||
| + | $ printf ' | ||
| + | $ apt-get update | ||
| + | $ apt-get install wireguard | ||
| + | $ reboot | ||
| + | |||
| + | Aktivieren von IPv4 forwarding in der / | ||
| + | |||
| + | # Uncomment the next line to enable packet forwarding for IPv4 | ||
| + | net.ipv4.ip_forward = 1 | ||
| + | |||
| + | Den Pi neu starten und die Änderungen nochmal überprüfen. | ||
| + | $ sysctl net.ipv4.ip_forward | ||
| + | net.ipv4.ip_forward = 1 | ||
| + | | ||
| + | ===== Keys generieren ===== | ||
| + | |||
| + | Die Erstellung der keys wird im Verzeichnis / | ||
| + | Um sicherzustellen dass alle Dateien die richtigen Berechtigungen haben, muss die umask auf 077 gesetzt sein. | ||
| + | $ umask 077 | ||
| + | Server Key generieren | ||
| + | |||
| + | private und public key für den Server | ||
| + | $ wg genkey | tee server-private.key | wg pubkey > server-public.key | ||
| + | $ ls -l server* | ||
| + | -rw------- 1 root root 45 Mar 31 10:38 server-private.key | ||
| + | -rw------- 1 root root 45 Mar 31 10:38 server-public.key | ||
| + | |||
| + | ===== Client Keys generieren ===== | ||
| + | |||
| + | private und public key für die Clients | ||
| + | $ wg genkey | tee client1-private.key | wg pubkey > client1-public.key | ||
| + | $ wg genkey | tee client2-private.key | wg pubkey > client2-public.key | ||
| + | |||
| + | $ ls -l client* | ||
| + | -rw------- 1 root root 45 Mar 31 10:41 client1-private.key | ||
| + | -rw------- 1 root root 45 Mar 31 10:41 client1-public.key | ||
| + | -rw------- 1 root root 45 Mar 31 10:41 client2-private.key | ||
| + | -rw------- 1 root root 45 Mar 31 10:41 client2-public.key | ||
| + | |||
| + | ===== Server Konfiguration ===== | ||
| + | |||
| + | Dazu wird die Datei / | ||
| + | Bei den iptables Regeln muss ggf. noch der Name der Netzwerkschnittstelle angepasst werden! Bei mir ist es eth0. | ||
| + | |||
| + | [Interface] | ||
| + | Address = 10.10.10.1/ | ||
| + | ListenPort = 51820 | ||
| + | PrivateKey = < | ||
| + | PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | ||
| + | PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j | ||
| + | # Client1 Smartphone | ||
| + | [Peer] | ||
| + | PublicKey = < | ||
| + | AllowedIPs = 10.10.10.2/ | ||
| + | # Client2 Notebook | ||
| + | [Peer] | ||
| + | PublicKey = < | ||
| + | AllowedIPs = 10.10.10.3/ | ||
| + | Client Konfiguration | ||
| + | |||
| + | Für jeden Client erstelle ich eine eigene Konfigurationsdatei. | ||
| + | |||
| + | / | ||
| + | [Interface] | ||
| + | PrivateKey = < | ||
| + | Address = 10.10.10.2 | ||
| + | DNS = 192.168.150.20 | ||
| + | [Peer] | ||
| + | PublicKey = < | ||
| + | Endpoint = vpn.your-public-server.net: | ||
| + | AllowedIPs = 0.0.0.0/0, 192.168.150.0/ | ||
| + | PersistentKeepalive = 25 | ||
| + | |||
| + | / | ||
| + | [Interface] | ||
| + | PrivateKey = < | ||
| + | Address = 10.10.10.3 | ||
| + | DNS = 192.168.150.20 | ||
| + | [Peer] | ||
| + | PublicKey = < | ||
| + | Endpoint = vpn.your-public-server.net: | ||
| + | AllowedIPs = 0.0.0.0/0, 192.168.150.0/ | ||
| + | PersistentKeepalive = 25 | ||
| + | |||
| + | Als DNS Server nutze ich meinen eigenen im lokalen LAN und mit 0.0.0.0/0 wird alles (der komplette traffic) durch das VPN geroutet. | ||
| + | Da ich mich hinter einem NAT befinde, wird mit PersistentKeepalive = 25 versucht die Verbindung aufrecht zu halten. | ||
| + | WireGuard starten | ||
| + | $ wg-quick up wg0 | ||
| + | [#] ip link add wg0 type wireguard | ||
| + | [#] wg setconf wg0 /dev/fd/63 | ||
| + | [#] ip address add 10.10.10.1 dev wg0 | ||
| + | [#] ip link set mtu 1420 up dev wg0 | ||
| + | [#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | ||
| + | |||
| + | ===== WireGuard beim Systemstart automatisch laden. ===== | ||
| + | |||
| + | $ systemctl enable wg-quick@wg0 | ||
| + | Created symlink / | ||
| + | |||
| + | ===== WireGuard Status ===== | ||
| + | |||
| + | Status der aktiven wg0 Schnittstelle. | ||
| + | $ wg | ||
| + | interface: wg0 | ||
| + | public key: 9EHJpPuO59RsFbejPZacyZ34TkT7Exas/ | ||
| + | private key: (hidden) | ||
| + | listening port: 51820 | ||
| + | peer: mSOXtoZPSCoZL48u9IZGlpov5T4jAwZ7yhETTDosHVU= | ||
| + | allowed ips: 10.10.10.2/ | ||
| + | peer: 9q9PAKC5MUNaF4QmcH5hoqwpWoX2R4/ | ||
| + | allowed ips: 10.10.10.3/ | ||
| + | | ||
| + | ===== Firewall Konfiguration ===== | ||
| + | |||
| + | Der UDP Port 51820 muss an den internen VPN Server weitergeleitet werden. (hier für meinen MikroTik Router) | ||
| + | /ip firewall filter | ||
| + | add action=accept chain=forward dst-port=51820 protocol=udp | ||
| + | /ip firewall nat | ||
| + | add action=dst-nat chain=dstnat dst-port=51820 in-interface=wan protocol=udp to-addresses=192.168.150.200 to-ports=51820 | ||
| + | | ||
| + | ===== Road Warrior – Android Client ===== | ||
| + | |||
| + | Für Android nehme ich die offizielle WireGuard App aus dem Google Play Store. | ||
| + | |||
| + | Die Einstellungen der App kann mittels einer Datei, QR-Code oder manuell erfolgen. Auf dem Server wird ein QR-Code für den Client1 erstellt. | ||
| + | $ apt install -y qrencode | ||
| + | |||
| + | QR-Code für den Client1 erstellen. | ||
| + | $ qrencode -t ansiutf8 < client1.conf | ||
| + | |||
| + | Abscannen und fertig. Ohne die mühselige tipperei auf dem Smartphone. | ||
| + | |||
| + | ===== Road Warrior – Windows Client ===== | ||
| + | |||
| + | Für Windows nehme ich den offiziellen WireGuard Client. | ||
| + | Nach der Installation die (auf dem Server erzeugte) client2.conf importierenund die VPN Verbindung aktivieren. | ||
| + | |||
| + | ===== WireGuard updaten ===== | ||
| + | |||
| + | Das hat mich schon viel Nerven gekostet, weil nach einem Kernel Update des Systems wireguard-dkms nicht mehr kompiliert und mit einer Fehlermeldung abbricht. Sollte es mal Probleme geben, kann man folgendes versuchen. | ||
| + | # Variante A (nach jedem Kernel Update) | ||
| + | $ dpkg-reconfigure wireguard-dkms | ||
| + | # Variante B | ||
| + | $ apt remove wireguard* | ||
| + | $ apt install bc libncurses5-dev | ||
| + | $ apt install wireguard | ||
| + | |||
| + | Mittlerweile kompiliere ich mir dir WireGuard Kernel Module und das wg Tool selber. Ist super einfach und schnell erledigt. | ||
| + | WireGuard nicht aus den Repos installieren und ggf. installierte Pakete vorher deinstallieren! | ||
| + | # Toolchain installieren | ||
| + | $ apt-get install libmnl-dev libelf-dev linux-headers-$(uname -r) build-essential pkg-config | ||
| + | # WireGuard empfiehlt den aktuellen Snapshot zu verwenden | ||
| + | $ wget https:// | ||
| + | # Kernel Module und das wg Tool kompilieren (dauert noch keine 2 Minuten) | ||
| + | $ cd WireGuard-0.0.2019mmdd/ | ||
| + | $ make | ||
| + | # als root installieren | ||
| + | $ make install | ||
| + | # neustarten und fertig | ||
| + | $ reboot | ||
| + | |||
| + | WireGuard Compiling the Kernel Module from Source | current Snapshot versions | ||
| + | |||
| + | Die installierte Version kann man gut mit dmesg herausfinden. | ||
| + | $ dmesg | grep wireguard | ||
| + | [ | ||
| + | [ | ||
| + | [ | ||
| + | # etwas kompakter | ||
| + | $ dmesg | awk '/ | ||
| + | WireGuard 0.0.20191212 | ||
| + | |||
| + | ==== Fazit ===== | ||
| + | |||
| + | Im Vergleich zu OpenVPN ist die Einrichtung und Konfiguration, | ||
| + | Der Tunnelaufbau und das Routing funktionierten auf Anhieb reibungslos und schnell. | ||
| + | |||
| + | 17.05.2019 – Nach ca. 6 Wochen bin ich immer noch mehr als zufrieden! Schneller Tunnelaufbau und immer eine stabile Verbindung! | ||
| + | Links | ||
| + | |||
| + | * | ||
| + | * | ||
| + | * | ||
| + | * | ||