Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active April 2, 2020 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/2a6733cd6fe7bd5e631d8909ca4d2e83 to your computer and use it in GitHub Desktop.
Save miguelmota/2a6733cd6fe7bd5e631d8909ca4d2e83 to your computer and use it in GitHub Desktop.
Linux wireguard setup server and client
# arch install: https://gist.github.com/miguelmota/0515421a743ac705d40a40ae6d2f1042
sudo -s -H
mkdir -p /etc/wireguard/keys
cd /etc/wireguard/keys
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
vim /etc/wireguard/wg0.conf
wg-quick up wg0
# ubuntu install: https://gist.github.com/miguelmota/7aea0be31895b7d1c148afcadcce0bea
sudo -s -H
mkdir -p /etc/wireguard/keys
cd /etc/wireguard/keys
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
vim /etc/wireguard/wg0.conf
wg-quick up wg0
systemctl enable wg-quick@wg0.service
vim /etc/sysctl.conf
# uncomment line
# net.ipv4.ip_forward=1
sysctl -p
cat /proc/sys/net/ipv4/ip_forward # 1
[Interface]
PrivateKey = <client private key>
Address = 10.0.0.2/32
DNS = 1.1.1.1
[Peer]
PublicKey = <server public key>
Endpoint = <server public ip>:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
[Interface]
PrivateKey = <server private key>
Address = 10.0.0.1/24
ListenPort = 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 public key>
AllowedIPs = 10.0.0.2/32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment