Edge Router X WireGuard構築してみた

最近購入したEdge Router XでWireGuardを動かせるそうなのでやってみました。
以前にUbuntu 20.04でやってみましたが、今回はガチモンのルータでやってみます。

毎回恒例の参考記事の紹介と謝辞です。ありがとうございます。
www.blog.slow-fire.net
neontom.com

インストーラをERXへアップロード

SCPを使ってERXへアップロードします。

$ scp e50-v2-v1.0.20200506-v1.0.20200510.deb ubnt@192.168.1.1:/home/ubnt
Welcome to EdgeOS

By logging in, accessing, or using the Ubiquiti product, you
acknowledge that you have read and understood the Ubiquiti
License Agreement (available in the Web UI at, by default,
http://192.168.1.1) and agree to be bound by its terms.

ubnt@192.168.1.1's password:
e50-v2-v1.0.20200506-v1.0.20200510.deb        100%  167KB   7.1MB/s   00:00

WireGuardのインストール

# dpkg -i e50-v2-v1.0.20200506-v1.0.20200510.deb

下記の通りに表示されていればOK

Unpacking wireguard (1.0.20200506-2) ...
Setting up wireguard (1.0.20200506-2) ...

ERXでの諸々の設定

wg genkey | tee /config/auth/wg.key | wg pubkey > wg.public
set interfaces wireguard wg0 address 10.255.255.1/24
set interfaces wireguard wg0 listen-port 51820
set interfaces wireguard wg0 route-allowed-ips true
set interfaces wireguard wg0 private-key /config/auth/wg.key
set firewall name WAN_LOCAL rule 20 action accept
set firewall name WAN_LOCAL rule 20 description 'WireGuard'
set firewall name WAN_LOCAL rule 20 destination port 51820
set firewall name WAN_LOCAL rule 20 protocol udp
commit; save; exit

インターフェースの公開鍵の確認

root@ubnt:~$ sudo wg 
interface: wg0
  public key: *****************************
  private key: (hidden)
  listening port: 51820

ここまででERXでの設定8割完了です。

クライアント端末設定

今回クライアント端末はWindowsで検証しました。
まずはWireGuardのWindowsクライアントを入手します。
こちらからDLしてください

クライアントの起動と設定

クライアントを起動後、画面左下の「トンネルの追加」>「空のトンネルの追加」をクリックする。
すると公開鍵と秘密鍵が勝手に作ってくれている。
f:id:kyamisama:20201011164905p:plain

続いて下記のように設定を追加していく。
f:id:kyamisama:20201011164921p:plain

[Interface]
PrivateKey = <クライアント側の秘密鍵>
Address = 10.255.255.2/24

[Peer]
PublicKey = <ERX側の公開鍵>
AllowedIPs = 0.0.0.0/0
Endpoint = 192.168.1.1:51820

ERXでクライアントの設定

set interfaces wireguard wg0 peer <クライアントの公開鍵> allowed-ips 10.255.255.2/32

以上で設定完了です。
クライアントアプリから有効化し、10.255.255.1へのPingが飛ぶ事を確認しましょう。