Wireguard のセットアップメモ

Wireguard はオープンソースの VPN ソフトウェアである。 簡単に設定できて、 Linux , Windows , MacOS , iOS , Android といった、様々なプラットフォームで利用できる。

以下は Ubuntu 20.04 をサーバ、 MacOS をクライアントとした場合の設定方法の例である。

サーバの立ち上げ

sudo -i
apt update
apt upgrade
apt install wireguard
cd /etc/wireguard/
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
cat <<EOF > wg0.conf
[Interface]
Address = 192.168.8.1/24
ListenPort = 51820
PrivateKey = $(cat privatekey)

EOF
exit
ufw allow 51820/udp
ufw status
systemctl enable wg-quick@wg0
systemctl start wg-quick@wg0
systemctl status wg-quick@wg0
ip a show wg0
wg
exit

最後にサーバの公開鍵が表示される。

クライアントのセットアップ

App Store からダウンロード

トンネルの設定を記述。

[Interface]
PrivateKey = <あらかじめ設定されるプライベートキー>
Address = 192.168.8.16/24
DNS = 1.1.1.1

[Peer]
PublicKey = <サーバの公開鍵>
AllowedIPs = 192.168.8.1/24
Endpoint = <サーバのアドレス>:51820

画面にクライアントの公開鍵が表示される。

サーバ側のピアのセットアップ

sudo cat <<EOF >> /etc/wireguard/wg0.conf
[Peer]
PublicKey = <クライアントの公開鍵>
AllowedIPs = 192.168.8.16/32

EOF

トンネルのアクティベート

クライアント側でトンネルをアクティベートする。