WireGuard
- https://github.com/netbirdio/netbird - managed wireguard
- https://github.com/NHAS/wag - 2FA for wireguard
- https://github.com/notthebee/ansible-easy-vpn - from german kid
- https://www.wireguardconfig.com/ - config generator
Debugging
- Had to lower MTU to 1200
echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control # seems to turn it off echo module wireguard -p > /sys/kernel/debug/dynamic_debug/control sudo LOG_LEVEL=verbose wg show
Reload without stopping
# Reloads config without disrupting current peer sessions, # but does not re-run PostUp commands wg syncconf wg0 <(wg-quick strip wg0)
DNS
- How to Add dnsmasq and keep systemd-resolved (18.04 to 20.04)
apt update apt install dnsmasq vi /etc/dnsmasq.conf interface=wg0 bind-interfaces domain-needed bogus-priv filterwin2k systemctl restart dnsmasq systemctl enable dnsmasq netstat -antup killall -1 dnsmasq
systemd-resolve == resolvectl # in old documentsConfigure Wireguard with dnsmasq
# systemctl edit dnsmasq [Unit] After=wg-quick@wg0.service Wants=wg-quick@wg0.service- debugging
ubus call system board; uci show network; uci show firewall; uci show dhcp; ip address show; ip route show table all; ip rule show; iptables-save; head -v -n -0 /etc/resolv.* /tmp/resolv.* /tmp/resolv.*/*; netstat -l -n -p | grep -e dnsmasq
- How to Add dnsmasq and keep systemd-resolved (18.04 to 20.04)
Docs
- Endpoints and IP Addresses — good pics
Firewall
Tips
- Algo - Scripts to deploy wg
Setup
In NetworkManager - Newer Ubuntu
- Wireguard Setup - Lawrence Services
More than one interface
working server
[Interface] PrivateKey = 2GfdgcwgLfj+xxx= Address = 10.0.0.1/24 ListenPort = 51820 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 = yyy+HhSjSG8= AllowedIPs = 10.0.0.2/32, 192.168.1.102/32
working client
root@x:/etc/wireguard# cat wg0.conf [Interface] Address = 10.0.0.2/32 PrivateKey = xxx= DNS = 1.1.1.1 [Peer] PublicKey = yyy= Endpoint = 44.240.124.230:51820 PersistentKeepalive = 10 #AllowedIPs = 0.0.0.0/0, ::/0 AllowedIPs = 10.0.0.1/32,172.31.17.247/32
Reverse Proxy Server on the Internet
- Uses NGINX for web
- rinetd for non-web
- ssh -p 22022 home.overton-farms.com
Full setup
- Debian Setup - good. links at bottom
# -------- # server vi /etc/sysctl.conf # enable forwarding apt install wireguard cd /etc/wireguard wg genkey | tee privatekey | wg pubkey > publickey cat /etc/wireguard/wg0.conf [Interface] Address = 10.11.ll.1/24 ListenPort = 51811 PrivateKey = xxx= 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 = xxx= AllowedIPs = 10.11.11.2/32 wg-quick up wg0 systemctl enable wg-quick@wg0.service # VPC CIDRs account, name, CIDR A2, default, 172.31.0.0/16 Prod, default, 172.31.0.0/16 dev, default, 172.31.0.0/16 dev, network-dev, 10.0.0.0/16 dev, vpc-db, 172.30.0.0/16 d1, default 172.31.0.0/16 should stay empty d1, d1-prod 10.4.0.0/16 d2, d2-prod 10.1.0.0/16
How to get started with WireGuard VPN
apt update apt install wireguard apt install wireguard-tools # on newer ubuntu # if wg-quick up fails apt install openresolv # if routing vi /etc/sysctl.conf net.ipv4.ip_forward=1 # apply sysctl -p # gen key cd /etc/wireguard umask 077 wg genkey | tee privatekey | wg pubkey > publickey # server config vi /etc/wireguard/wg0.conf [Interface] PrivateKey = <contents-of-server-privatekey> Address = 10.0.0.1/24 ListenPort = 51820 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 = <contents-of-client-publickey> AllowedIPs = 10.0.0.2/32- Enable the service
wg-quick up wg0 wg show systemctl enable wg-quick@wg0 systemctl start wg-quick@wg0 # may have to wg-quick down wg0
Utility
ncat server
#!/bin/bash # SPDX-License-Identifier: GPL-2.0 # # Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. set -e [[ $UID == 0 ]] || { echo "You must be root to run this."; exit 1; } exec 3<>/dev/tcp/demo.wireguard.com/42912 privatekey="$(wg genkey)" wg pubkey <<<"$privatekey" >&3 IFS=: read -r status server_pubkey server_port internal_ip <&3 [[ $status == OK ]] ip link del dev wg0 2>/dev/null || true ip link add dev wg0 type wireguard wg set wg0 private-key <(echo "$privatekey") peer "$server_pubkey" allowed-ips 0.0.0.0/0 endpoint "demo.wireguard.com:$server_port" persistent-keepalive 25 ip address add "$internal_ip"/24 dev wg0 ip link set up dev wg0 if [ "$1" == "default-route" ]; then host="$(wg show wg0 endpoints | sed -n 's/.*\t\(.*\):.*/\1/p')" ip route add $(ip route get $host | sed '/ via [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/{s/^\(.* via [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/}' | head -n 1) 2>/dev/null || true ip route add 0/1 dev wg0 ip route add 128/1 dev wg0 fi
Wrappers
Subspace Controller
- https://github.com/subspacecommunity/subspace — wireguard controller SSO and SAML
Managed Providers
ZeroTier
- https://www.zerotier.com/ - Uses Wireguard? Uses parts of wg written in Rust
Troubleshoot
sudo tcpdump -nn -i wg0 sudo tcpdump -nn -i eth0 udp and port 51820 tcpdump -nn 'udp and (port 51888 or 51840 or 51811)'
Tailscale
- commercial wireguard
ZeroTier
- https://www.zerotier.com/ - Uses Wireguard? Uses parts of wg written in Rust
Scrubbed copy of config
# Notes # reload wg syncconf wg0 <(wg-quick strip wg0) systemctl stop wg-quick@wg0.service; wg-quick up wg0 wg-quick down wg0; sleep 2; wg-quick up wg0 service dnsmasq start; killall -1 dnsmasq systemctl status dnsmasq.service systemctl stop dnsmasq.service systemctl start dnsmasq.service # wg0.conf root@x-bastion:/etc/wireguard# cat wg0.conf [Interface] PrivateKey = 4GhOOKu3UOnMp+xxxx= Address = 10.88.88.1/24 ListenPort = 51888 MTU = 1420 DNS = 127.0.0.1 # IP forwarding PreUp = sysctl -w net.ipv4.ip_forward=1 # IP masquerading PreUp = iptables -t mangle -A PREROUTING -i wg0 -j MARK --set-mark 0x30 PreUp = iptables -t nat -A POSTROUTING ! -o wg0 -m mark --mark 0x30 -j MASQUERADE PostDown = iptables -t mangle -D PREROUTING -i wg0 -j MARK --set-mark 0x30 PostDown = iptables -t nat -D POSTROUTING ! -o wg0 -m mark --mark 0x30 -j MASQUERADE # --- Myron mac14 [Peer] PublicKey = xx= AllowedIPs = 10.88.88.4/32 PersistentKeepalive = 9 ...