転載・引用について

ユーザ用ツール

サイト用ツール


tweet:2020:0611_01
no way to compare when less than two revisions

差分

このページの2つのバージョン間の差分を表示します。


前のリビジョン
tweet:2020:0611_01 [2020/06/11 19:29] (現在) – [WireGuardのconfiguration] seirios
行 1: 行 1:
 +====== FreeBSDでWireGuard ======
  
 +OpenVPNも悪くないのだが、やっぱり「証明書の更新」がなかなかに厳しい。というわけで、WireGuardを試してみる。
 +
 +===== WireGuardとOpenVPNの比較 =====
 +
 +TBD
 +
 +===== Network構造(Site-to-Site VPN) =====
 +
 +<code>
 +                  (192.0.2.1)   (198.51.100.1)        |
 + [NodeA]---+---[VPNR-A]------(Internet)------[VPNR-B]---+---[NodeB]
 +     (10)  |  (1)     \(1)                (2)/     (2)  |   (20)
 +10.1.1.0/24|           +--------------------+           |10.2.2.0/24
 +                          10.255.255.0/24
 +
 +Site A <------------->|<-------Internet------>|<----------> Site B
 +</code>
 +
 +  * Site A と Site B をVPNで結ぶ
 +  * Site AのNetworkは10.1.1.0/24、Site BのNetworkは10.2.2.0/24
 +  * VPNR-AのGlobal Addressは 192.0.2.1、VPNR-BのGlobal Addressは 198.51.100.1
 +  * Tunnel Networkは、10.255.255.0/24
 +  * VPNR-AのTunnel IP Addressは10.255.255.1、VPNR-BのTunnel IP Addressは10.255.255.2
 +  * WireGuardの待ち受けポートを**UDP/65534**とする
 +
 +とする。
 +
 +===== WireGuardのInstall =====
 +
 +FreeBSD以外へのInstallは、いくらでも記事があるので、ここでは割愛。
 +
 +  - FreeBSDをRouterにする
 +    * (CMD) sysctl -w net.inet.ip.forwarding=1
 +    * (rc.conf) gateway_enable="YES"
 +  - Packet filterを利用している場合、適当にUDP/65534を開ける
 +  - Wireguardをinstallする
 +    * ''pkg install wireguard''
 +  - 起動時にWireguardが動作するようにrc.confに以下を追記
 +    * ''wireguard_enable="YES"''
 +    * ''wireguard_interfaces="wg0"''
 +
 +これで、Install完了
 +
 +===== WireGuardのconfiguration =====
 +
 +  - 鍵を作成
 +    * VPNR-A
 +      * <code>
 +# cd /usr/local/etc/wireguard
 +# wg genkey | tee A.private.key | wg pubkey > A.public.key
 +# cat A.private.key
 +1StlE/SHru2lOOoU+SLaA+SPLAYC+SCLOGUC0A+WaIMM=
 +# cat A.public.key
 +wla6Straum0tHReu+woMm/4gruyscrOMaa+thrai/kro=
 +</code>
 +    * VPNR-B
 +      * <code>
 +# cd /usr/local/etc/wireguard
 +# wg genkey | tee B.private.key | wg pubkey > B.public.key
 +# cat B.private.key
 +Xy8vOTORR2TrAAS3STRAY+TYVrAi+ROOTruId2tHlIPA=
 +# cat B.public.key
 +7CYhEISH9She0WRUo0WrA+1tRAY/BLu8XoT/UL+SHLAY=
 +</code>
 +  - 設定ファイルを作成
 +    * VPNR-A:/usr/local/etc/wireguard/wg0.conf
 +      * <code>
 +# Wireguard configuration.
 +[Interface]
 +Privatekey = 1StlE/SHru2lOOoU+SLaA+SPLAYC+SCLOGUC0A+WaIMM=
 +Address = 10.255.255.1/24
 +ListenPort = 65534
 +
 +[Peer]
 +PublicKey = 7CYhEISH9She0WRUo0WrA+1tRAY/BLu8XoT/UL+SHLAY=
 +AllowedIPs = 10.255,255,2/32, 10.2.2.0/24
 +Endpoint = 192.0.2.1:65534
 +
 +</code>
 +    * VPNR-B:/usr/local/etc/wireguard/wg0.conf
 +      * <code>
 +# Wireguard configuration.
 +[Interface]
 +Privatekey = Xy8vOTORR2TrAAS3STRAY+TYVrAi+ROOTruId2tHlIPA=
 +Address = 10.255.255.2/24
 +ListenPort = 65534
 +
 +[Peer]
 +PublicKey = wla6Straum0tHReu+woMm/4gruyscrOMaa+thrai/kro=
 +AllowedIPs = 10.255.255.1/32, 10.1.1.0/24
 +Endpoint = 198.51.100.1:65534
 +</code>
 +
 +===== Wireguardの起動他 =====
 +
 +  * Wireguardの起動
 +    * ''service wireguard start''
 +  * Wireguardの状態確認
 +    * ''wg show''
 +      * Interfaceの状態、peerの状態などが出力される
 +  * wireguardのversion確認
 +    * ''wireguard-go help''
 +  * 他に、wg-quickコマンドもあるが、今回は割愛
 +  * Wireguardの停止
 +    * ''service wireguard stop''
 +
 +=====  注意 =====
 +  * [Node A]のdefault routeがVPNR-Aを向いている かつ [Node B]のdefault routeがVPNR-Bを向いている(もしくはstatic routeが切られている)場合に、[Node A]と[Node B]がVPNトンネル経由で通信できる。
 +  * WireGuardは、L3 Tunnelを掘るためのApplicationなので、OpenVPNやSoftEtherのようなL2 VPNを掘ることはできない。
 +  * WireGuardは通信にUDPを利用するので、PacketFilter Firewallの設定が難しいことがある。
tweet/2020/0611_01.txt · 最終更新: 2020/06/11 19:29 by seirios

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki