WireGuard
はじめに
私は格安VPSサービスのLunaNodeを「ひいき」にしてます。 最安プランは月3.5ドルで、任意のインストーラISOイメージでOSを導入できます。 このサーバもLunaNodeの最安プランで建てている訳ですが、さすがに非力なので、VPNで自宅の非公開サーバを接続して拡張しています。
🌐 インターネット
│
▼
🖥️ リモートVPSサーバ
(Public IP)
│
──VPN接続(🔒)──
│
▼
🏠 自宅非公開サーバ
(Private IP, NAT背後)
私はVPNを使うのは、ほぼ初めてだったので、手軽と噂のWireGuardを使う事にしました。 以下は設定の手順のメモです。 基本的には、未来の自分の為に残す主旨です。 質問があれば、分かる処は答えます。
構成
VPSではOSは Devuan GNU+Linux を使ってます。 基本的には Debian GNU/Linux と同じですが、 systemd を排除してるので、デーモン(サービス)の管理の仕方も多少異なります。
自宅非公開サーバではOSは OpenBSD を使ってます。
どちらのサーバにもVPNツールの WireGuard を導入しますが、WireGuardに関してはDevuanをサーバ、OpenBSDをクライアントとして使います。
Devuan側
# apt-get install wireguard
# touch privatekey
# chmod 600 privatekey
# wg genkey > privatekey
# wg pubkey < privatekey > publickey
# touch wg0.conf
# chmod 600 wg0.conf
# vi wg0.conf
# vi /etc/network/interfaces
# service networking restart
# ufw allow 51820
/etc/wireguard/wg0.conf
[Interface]
Address = 10.0.0.1/24
PrivateKey = <Devuanのプライベートキー>
ListenPort = 51820
[Peer]
PublicKey = <OpenBSDのパブリックキー>
AllowedIPs = 10.0.0.2/32
#Endpoint = <OpenBSDのグローバルIP>:51820
PersistentKeepalive = 25
/etc/network/interfaces
auto wg0
iface wg0 inet manual
pre-up /usr/bin/wg-quick up wg0
post-down /usr/bin/wg-quick down wg0
OpenBSD側
# pkg_add wireguard-tools
# mkdir /etc/wireguard
# touch privatekey
# chmod 600 privatekey
# wg genkey > privatekey
# wg pubkey < privatekey > publickey
# touch wg0.conf
# chmod 600 wg0.conf
# vi wg0.conf
# vi /etc/pf.conf
# pfctl -f /etc/pf.conf
# wg-quick up wg0
/etc/wireguard/wg0.conf
[Interface]
Address = 10.0.0.2/24
PrivateKey = <OpenBSDのプライベートキー>
#ListenPort = 51820
[Peer]
PublicKey = <Devuanのパブリックキー>
AllowedIPs = 10.0.0.1/32
Endpoint = <DevuanのグローバルIP>:51820
PersistentKeepalive = 25
/etc/pf.conf
# VPN
pass in on wg0 proto tcp from 10.0.0.1 to 10.0.0.2
pass in on wg0 proto tcp to re0 port http
/etc/rc.d/wireguard
#!/bin/sh
case "$1" in
start)
wg-quick up wg0
;;
stop)
wg-quick down wg0
;;
restart)
wg-quick down wg0
wg-quick up wg0
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0