Skip to main content

WireGuard

ID 107
Name WireGuard
OS Ubuntu 20.04.3 LTS
Root Disk 8 G
RAM 512 M
Cores 1
Netzwerk 192.168.1.220

Obligatorisches Update

apt update && apt upgrade -y

Installation WireGuard

wget git.io/wireguard -O wireguard-install.sh && bash wireguard-install.sh

Neuen Benutzer hinzufügen

bash wireguard-install.sh 

Falls eine Konfigurationsdatei anstatt des QR-Codes benötigt wird, ist die Dateifreigabe via SSH nötig. Somit:

nano /etc/ssh/sshd_config


Neustart des ssh-Servers

service ssh restart

Wireguard Site2Site

Quelle: https://apfelcast.com/site-to-site-vpn-einfach-mit-wireguard-einrichten-schritt-fuer-schritt-anleitung/

Auf einem Proxmox-Server müssen dem LXC noch Rechte eingeräumt werden:

### Vorbereitung ###

nano /etc/pve/lxc/123.conf
lxc.cgroup.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net dev/net none bind,create=dir
chown 100000:100000 /dev/net/tun

########Restart/Start LXC

### Create WireGuard Site-to-Site VPN ######## 

example data:
subnet site-1: 192.168.0.0/24
subnet site-2: 192.168.178.0/24

--> on site 1 and 2
## install WireGuard ##

apt install wireguard

## enbale ip forwarding ##

nano /etc/sysctl.conf

uncomment net.ipv4.ip_forward=1

## apply changes ##

sysctl -p

## generate public and private keys ##

cd /etc/wireguard
umask 077; wg genkey | tee privatekey | wg pubkey > publickey

--> site 1 (server)

## create wg0.conf

nano /etc/wireguard/wg0.conf
[Interface] 
PrivateKey = <site-1 private-key>
Address = 10.0.0.1/24
SaveConfig = true 
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
ListenPort = 51820

[Peer]
PublicKey = <site-2 public-key>
AllowedIPs = 10.0.0.0/24, 192.168.178.0/24
PersistentKeepalive = 25

--> site 2 (client)

## create wg0.conf

[Interface] 
PrivateKey = <site-2 private-key>
Address = 10.0.0.3/24
SaveConfig = true 
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] 
PublicKey = <site-1 public-key>
Endpoint = <FQDN>:51820 
AllowedIPs = 10.0.0.0/24, 192.168.0.0/24
PersistentKeepalive = 25

--> on site 1 and 2

## start connection ##

wg-quick up wg0

## show status ##

wg show

## enable on system boot ##

systemctl enable wg-quick@wg0