Created
December 31, 2023 08:17
-
-
Save darcyliu/2ff91e872a854fc313c2444ca40a18ca to your computer and use it in GitHub Desktop.
Setup WireGuard on FreeBSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pkg install -y wireguard wireguard-tools | |
cd /usr/local/etc/wireguard/ | |
umask 077 | |
wg genkey > freebsd.private | |
wg pubkey < freebsd.private > freebsd.public | |
wg genkey > client.private | |
wg pubkey < client.private > client.public | |
SERVER_PRIVATE_KEY=$(cat freebsd.private) | |
CLIENT_PUBLIC_KEY=$(cat client.public) | |
cat > wg0.conf <<EOF | |
[Interface] | |
Address = 10.10.10.1/32 | |
ListenPort = 12345 | |
PrivateKey = $SERVER_PRIVATE_KEY | |
[Peer] | |
AllowedIPs = 10.10.20.2/32 | |
PublicKey = $CLIENT_PUBLIC_KEY | |
EOF | |
CLIENT_PRIVATE_KEY=$(cat client.private) | |
SERVER_PUBLIC_KEY=$(cat freebsd.public) | |
cat > client.conf <<EOF | |
[Interface] | |
PrivateKey = $CLIENT_PRIVATE_KEY | |
Address = 10.10.20.2/32 | |
DNS = 8.8.8.8 | |
[Peer] | |
PublicKey = $SERVER_PUBLIC_KEY | |
AllowedIPs = 0.0.0.0/0 | |
Endpoint = 1.2.3.4:12345 | |
PersistentKeepalive = 30 | |
EOF | |
service wireguard enable | |
sysrc wireguard_interfaces="wg0" | |
service wireguard start | |
pkg install -y libqrencode | |
qrencode -t ansi < client.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment