# Wireguard VPN

# Was ist Wireguard?

Wireguard ist ein moderner VPN Tunnel.

*In meinem Setup:*
```
Internet → Hetzner (46.54.2.140)
            ↓
      Wireguard-Tunnel (verschlüsselt)
            ↓
         Homeserver (10.100.0.2)
            ↓
         Services (Docker)
```

**Vorteile:**
  - Verschlüsselt
  - Schnell
  - Einfach
  - Stabil

# Installation auf Hetzner

**Auf Hetzner-Server:**

```
  ssh hetzner

# Wireguard installieren
  apt install -y wireguard

# Keys generieren
  cd /etc/wireguard
  umask 077
  wg genkey | tee hetzner-private.key | wg pubkey > hetzner-public.key

# Keys anzeigen und notieren!
  cat hetzner-private.key
  cat hetzner-public.key
```

**Config erstellen**
```
nano /etc/wireguard/wg0.conf
```
**Inhalt:**
``` ini
[Interface]
Address = 10.100.0.1/24
ListenPort = 51820
PrivateKey = <HETZNER_PRIVATE_KEY>

PostUp = sysctl -w net.ipv4.ip_forward=1
PostDown = sysctl -w net.ipv4.ip_forward=0

[Peer]
PublicKey = <HOMESERVER_PUBLIC_KEY>
AllowedIPs = 10.100.0.2/32
PersistentKeepalive = 25
```
**Aktivieren**
```bash
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p

systemctl enable wg-quick@wg0
systemctl start wg-quick@wg0
systemctl status wg-quick@wg0
```

# Installation auf Homeserver

**Auf Homeserver:**

```bash
# Wireguard installieren
  sudo apt update
  sudo apt install -y wireguard

# Keys generieren
  sudo -i
  cd /etc/wireguard
  umask 077
  wg genkey | tee homeserver-private.key | wg pubkey > homeserver-public.key

# Keys anzeigen und notieren!
  cat homeserver-private.key
  cat homeserver-public.key
```

**Config erstellen:**
```bash
sudo nano /etc/wireguard/wg0.conf
```

**Inhalt:**
```ini
[Interface]
Address = 10.100.0.2/24
PrivateKey = <HOMESERVER_PRIVATE_KEY>

[Peer]
PublicKey = <HETZNER_PUBLIC_KEY>
Endpoint = 46.224.8.110:51820
AllowedIPs = 10.100.0.1/32
PersistentKeepalive = 25
```

**Akivieren:**
```bash
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
sudo systemctl status wg-quick@wg0
```

# Tunnel setzen

**Von Hetzner zum Homeserver:**
```bash
# Auf Hetzner
  ping -c 4 10.100.0.2
```

**Von Homeserver auf Hetzner:**
```bash
# Auf Homeserver
  ping -c 4 10.100.0.1
```

-> Beide sollten Antworten

**Status prüfen**

```wg show```

**Troubleshooting**
```bash
# Wireguard neu starten
  sudo systemctl restart wg-quick@wg0
# Logs ansehen
  journalctl -u wg-quick@wg0 -f
```