Open5

WireGuard 構築

WisWis

40bitの乱数生成

> 245385749580

16進数に変換

> 0x392DEB7D8C

IPv6に当てはめる

> fd39:2deb:7d8c::/48
WisWis

パッケージをインストール

apt install wireguard wireguard-tools

鍵の生成

wg genkey > privatekey
wg pubkey < privatekey > publickey
wg genpsk > preshared

QR作成

apt install qrencode
qrencode -t PNG -r wg0.conf -o wg0.png
WisWis

サーバー

/etc/systemd/network/wg0.network
[Match]
Name = wg0

[Network]
Address = 10.39.0.1/24
Address = fd39::1/64
IPForward = yes
/etc/systemd/network/wg0.netdev
[NetDev]
Name = wg0
Kind = wireguard
MTUBytes = 1350

[WireGuard]
ListenPort = 51820
PrivateKey = <サーバーの秘密鍵>

[WireGuardPeer]
PublicKey = <クライアントの公開鍵>
AllowedIPs = 10.39.0.2/32, fd39::2/128

[WireGuardPeer]
#PresharedKey = <事前共有鍵>
PublicKey = <クライアントの公開鍵>
AllowedIPs = 10.39.0.3/32, fd39::3/128
networkctl reload
networkctl status wg0
WisWis

クライアント

/etc/systemd/network/wg0.network
[Match]
Name = wg0

[Network]
Address = 10.39.0.2/32
Address = fd39::2/128
/etc/systemd/network/wg0.netdev
[NetDev]
Name = wg0
Kind = wireguard
MTUBytes = 1350

[WireGuard]
PrivateKey = <クライアントの秘密鍵>

[WireGuardPeer]
PublicKey = <サーバー公開鍵>
Endpoint = <サーバーURL>:51820
AllowedIPs = 10.39.0.0/24, fd39::/64
PersistentKeepalive = 25

wg-quick

/etc/wireguard/wg0.conf
[Interface]
Address = 10.39.0.2/32, fd39::2/128
PrivateKey = <クライアントの秘密鍵>
MTU = 1350

[Peer]
Endpoint = <サーバーURL>:51820
PublicKey = <サーバー公開鍵>
AllowedIPs = 10.39.0.0/24, fd39::/64
PersistentKeepalive = 25