EZ WireGuard Setup

Keys

Generate keys on both the server and client.

1
wg genkey | tee privatekey | wg pubkey > publickey

Server

1
2
3
4
5
6
7
8
9
10
[Interface]
PrivateKey = <server private key>
ListenPort = 51820
Address = 10.0.0.1/24
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -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; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey = <client public key>
AllowedIPs = 10.0.0.0/24

Client

1
2
3
4
5
6
7
8
[Interface]
PrivateKey = <client private key>
Address = 10.0.0.2/24
[Peer]
PublicKey = <server public key>
Endpoint = <server public ip>:51820
AllowedIPs = 10.0.0.0/24

Run

1
wg-quick up wg0

Daemon

1
2
systemctl enable wg-quick@wg0
systemctl start wg-quick@wg0