Skip to content

Instantly share code, notes, and snippets.

@coopbri
Last active February 13, 2020 19:41
Show Gist options
  • Save coopbri/c804652f99fd628a0d2b4ea5b66c3eba to your computer and use it in GitHub Desktop.
Save coopbri/c804652f99fd628a0d2b4ea5b66c3eba to your computer and use it in GitHub Desktop.
Wireguard server and client template with iptables rules (peer-to-peer connection with one client)
/etc/wireguard/wg0-client.conf
--------------------------------------------------------------
[Interface]
Address = ($client-ipv4)/32
PrivateKey = $(client-privkey)
[Peer]
PublicKey = $(server-pubkey)
Endpoint = $(external-address):51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 21
/etc/wireguard/wg0.conf
--------------------------------------------------------------
[Interface]
Address = $(server-ipv4)/24
SaveConfig = true
PrivateKey = $(server-privkey)
ListenPort = $(external-address):51820
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 MASQUERADE
[Peer]
PublicKey = $(client-pubkey)
AllowedIPs = $(client-ipv4)/32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment