スマホでWireGuardクライアント
下準備
まずは鍵のペアを作ります。
# mkdir mobile && cd mobile
# ( umask 0077 && wg genkey | tee privatekey | wg pubkey > publickey )
サーバーを止めてからサーバーの設定ファイルに追記します。
# サーバーの設定ファイルがある場所へ移動
cd ..
# サービスを止めて設定ファイルを編集可能にします。編集してから止めると変更が失われます。
systemctl stop wg-quick@wg0
cat >> wg0.conf <<EOF
[Peer]
PublicKey = `cat mobile/publickey`
AllowedIPs = 192.168.11.4/32
EOF
クライアントの設定ファイルを作ります。
cd mobile
cat > wg0.conf <<EOF
[Interface]
PrivateKey = `cat privatekey`
## Client IP
Address = 192.168.11.4/24
## if you have DNS server running
# DNS = 192.168.11.1
[Peer]
PublicKey = `cat ../publickey`
## to pass internet trafic 0.0.0.0 but for peer connection only use 192.168.11.0/24, or you can also specify comma separated IPs
AllowedIPs = 192.168.11.0/24
Endpoint = SERVER_PUBLIC_IP:51820
PersistentKeepalive = 20
EOF
ここからがモバイルならではの工程です
クライアントの設定ファイルからQR CODEを作ります。
qrencode -t ansiutf8 < wg0.conf
とするとモバイルアプリの’Scan from QR code’でトンネルを作成できました:。