quick wireguard client setup
this article is mainly for my own future reference so don't rely on
these instructions for real security. this doesn't cover server
setup, just how i configured my laptop as a client.
on the client:
install wireguard and generate the required keys
$ sudo apt install wireguard
... apt output ...
$ wg genkey > private.key
$ wg pubkey < private.key > public.key
$ wg genkey > preshared.key
configure the client to connect to the server
$ sudo -e /etc/wireguard/wg0.conf
[Interface]
PrivateKey = $CONTENTS_OF_CLIENT_PRIVATE_KEY_FILE
# E.g. if your VPN uses the 10.1.0.0/16 subnet,
# you might use 10.1.0.101/32 here
Address = $CLIENT_VPN_IP
# Optional: set a DNS server(s) to use while on the VPN
DNS = $COMMA_SEPARATED_DNS_SERVERS
[Peer]
PublicKey = $SERVER_PUBLIC_KEY
PresharedKey = $CONTENTS_OF_PRESHARED_KEY_FILE
AllowedIPs = $IPS_VISIBLE_VIA_VPN # E.g. 0.0.0.0/0 to allow all
Endpoint = $WAN_SERVER_IP_AND_PORT
on the server:
add the new client to the bottom of your wireguard config
$ sudo -e /etc/wireguard/wg0.conf
[Peer]
PublicKey = $CONTENTS_OF_CLIENT_PUBLIC_KEY_FILE
PresharedKey = $CONTENTS_OF_PRESHARED_KEY_FILE
AllowedIPs = $CLIENT_VPN_IP
Endpoint = $LAN_GATEWAY_IP_AND_RANDOM_PORT
restart the vpn to load the new config
TODO: there's a faster way to do this with wg syncconf
but i can't be bothered to figure it out
$ sudo wg-quick down wg0 && sudo wg-quick up wg0
on the client
start wireguard and try out the connection
it should look something like this
$ sudo wg-quick up wg0
$ ping $SERVER_VPN_IP
PING 10.1.0.100 (10.1.0.100) 56(84) bytes of data.
... ping output ...
$ sudo wg show
interface: wg0
public key: xxxxxxxxxx
private key: (hidden)
listening port: 51234
peer: (server public key)
preshared key: (hidden)
endpoint: x.y.z.w:51280
allowed ips: 10.1.0.101/32
latest handshake: 2 minutes, 32 seconds ago
transfer: 3.40 KiB received, 3.79 KiB sent
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
written by peter beard on 2025-12-12, last updated 2025-12-12
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -