VPN: WireGuard

OpenVPNを代替する次世代VPNプロトコルのWireGuardの導入を進める。WireGuardはOpenVPNよりも高速で設定も簡単との噂。まずはopenSUSEにWireGuardをインストールする。

server # zypper install wireguard-tools

client # zypper install wireguard-tools

WireGuardはServer側、Client側のそれぞれで公開鍵を作成する。

server # wg genkey | tee wg_server.key | wg pubkey > wg_server.pub
server # chmod 600 wg_server.key
server # ls
wg_server.key  wg_server.pub
client # wg genkey | tee wg_client.key | wg pubkey > wg_client.pub
client # chmod 600 wg_client.key
client # ls
wg_client.key  wg_client.pub

server側にインタフェースwg0を作成する。今回はUDP: 51820ポートを使うので、Firewallや上位のルータの設定はあらかじめ完了しておく。

server # vi wg0.conf
[Interface]
PrivateKey = wg_server.keyの中身を記載
Address = 172.27.7.7/24
table = off
ListenPort = 51820

[Peer]
# client1
PublicKey = wg_client.pugの中身を記載
AllowedIPs = 172.27.7.9/32,192.168.32.0/22

AllowedIPsにはclient1側に存在するIPアドレスを記載する。設定は/etc/wireguardに置くのが流儀っぽい。ルーティングはOSPFで設定しているのでtable = offを設定し、WireGuardがルーティング設定を行わないようにする。

server # wg-quick up /etc/wireguard/wg0.conf
Warning: `/etc/wireguard/wg0.conf' is world accessible
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
Warning: AllowedIP has nonzero host part: 172.27.7.9/24
[#] ip -4 address add 172.27.7.7/24 dev wg0
[#] ip link set mtu 1420 up dev wg0

server # systemctl enable wg-quick@wg0

client側のインターフェースも設定する。

client # vi wg7.conf
[Interface]
PrivateKey = wg_client.keyの中身
Address = 172.27.7.9/24
table = off

[Peer]
PublicKey = wg_server.pubの中身
Endpoint = 接続先サーバのIPアドレスかドメイン:51820
AllowedIPs = 172.27.7.0/24,192.168.16.0/20

IPv6での接続もO.K.なようだ。

client # cp wg7.conf /etc/wireguard/wg7.conf
client # wg-quick up /etc/wireguard/wg7.conf
client # systemctl enable wg-quick@wg7

接続できることを確認したらOSPFの設定を変更して、OpenVPNよりもWireGuardを優先するように設定変更する。

frr01(config)# interface tun0
frr01(config)# description < OpenVPN Server Interface >
frr01(config)#  ip ospf cost 100
frr01(config)#  ip ospf network non-broadcast
frr01(config)#  ip ospf priority 255
frr01(config)# !
frr01(config)# interface wg0
frr01(config)# description < WireGuard Server Interface >
frr01(config)#  ip ospf cost 90
frr01(config)#  ip ospf network non-broadcast
frr01(config)#  ip ospf priority 255
frr01(config)# 
frr01(config)# do show ip ospf nei

Neighbor ID     Pri State           Dead Time Address         Interface       
3.3.3.3           0 Full/DROther      39.179s 172.26.40.28    tun0:172.26.40.1
3.3.3.3           0 Full/DROther      39.058s 172.27.7.9      wg0:172.27.7.7