SBクラウドの telescreen です。今回はリージョン間のVPN通信を実現する方法について書きたいと思います。
そもそも問題は何?
複数なリージョンを渡るサービスを運用すると、必ずデータ同期やリージョン間のAPI呼び出しなどのような問題が出てきます。重要なデータや内部のAPIの呼び出しの場合だと、公共なインターネットではなく安全な通信環境で行いたいですね。こんな時には、リージョン間のVPN接続環境を構築すれば良いです。
ソフトウェア VPNのソリューションの中では SoftEtherがあります。SoftEtherは VPNサーバとVPNブリッジ機能があり、この2つの機能を組み合わせることによってリージョン間の安全な接続をインターネット経由で実現できます。
この記事の残りは SoftEtherのVPNサーバとVPNブリッジ機能を使ってVPN通信環境の構築手順について書きます。
ネットワークの構成図
[caption id="attachment_483" align="aligncenter" width="550"] ネットワーク構成 (Source: https://ja.softether.org/4-docs/1-manual/A/10.5)[/caption]
AlibabaクラウドのECSサーバー上で、SoftEtherソフトウェアをデプロイします。Hub/ブリッジ機能を使うことで、ECSサーバーをVPNルーターのように稼働します。
構築手順
今回はAlibabaクラウドのシンガポールリージョンと東京リージョンの間のVPN通信を構築します
1. ECSサーバーを作成
今回は日本・シンガポール間のVPNネットワークを構築したいため、Alibabaクラウドの東京リージョンとシンガポールリージョンでそれぞれ1インスタンスを購入しました。インスタンスの情報は以下となります
リージョン | グローバルIP | ローカルIP | VPC サブネット |
シンガポール | 106.14.211.184 | 172.19.160.175 | 172.19.0.0/16 |
東京 | 47.74.20.205 | 10.2.219.148 | 10.2.0.0/16 |
2. SoftEther インストール
SoftEtherは公式ホームページからダウンロードし、ローカルファイルシステムに展開します。コンパイル用の Makefile ファイルが用意されたので、make コマンドで簡単にコンパイルできます。
[ecs-user@iZ6we2zi66htonflydzqgmZ ~]$ ls softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x64-64bit.tar.gz [ecs-user@iZ6we2zi66htonflydzqgmZ ~]$ tar xf softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x64-64bit.tar.gz [ecs-user@iZ6we2zi66htonflydzqgmZ ~]$ ls softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x64-64bit.tar.gz vpnserver [ecs-user@iZ6we2zi66htonflydzqgmZ ~]$ cd vpnserver [ecs-user@iZ6we2zi66htonflydzqgmZ ~]$ make
コンパイルが完了したら、vpnserverとvpncmd バイナリファイルが作成されます。
3. SoftEther 設定
[caption id="attachment_516" align="alignnone" width="696"] VPNハブ/VPNブリッジ構成[/caption]
- SoftEtherの初期設定 (ハブ作成、管理者パスワード)
- シンガポール側でカスケード接続用のアカウント作成
- 東京側でVPN接続を作成
- ECSのブリッジアダプターを作成・IP設定 (vpn_tapのIPは 192.168.30.0/24)
- ECSはお互いに疎通可能かどうか pingで確認
SoftEther 初期設定 (東京・シンガポールの両方のECSで実行)
sudo ./vpnserver ./vpncmd /server localhost VPN Server> ServerPasswordSet Connection has been established with VPN Server "localhost" (port 443). You have administrator privileges for the entire VPN Server. VPN Server>ServerPasswordSet ServerPasswordSet command - Set VPN Server Administrator Password Please enter the password. To cancel press the Ctrl+D key. Password: ***** Confirm input: ***** VPN Server> HubCreate VPN_HUB HubCreate command - Create New Virtual Hub Please enter the password. To cancel press the Ctrl+D key. Password: ***** Confirm input: ***** The command completed successfully.
シンガポール側でカスケード接続用のアカウント作成
VPN Server>hub VPN_HUB VPN Server/VPN_HUB>UserList UserList command - Get List of Users Item|Value ----+----- The command completed successfully. VPN Server/VPN_HUB>UserCreate vpnuser UserCreate command - Create User Assigned Group Name: User Full Name: VPN User User Description: VPN User The command completed successfully. VPN Server/VPN_HUB>UserList UserList command - Get List of Users Item |Value ----------------+----------------------- User Name |vpnuser Full Name |VPN User Group Name |- Description |VPN User Auth Method |Password Authentication Num Logins |0 Last Login |(None) Expiration Date |No Expiration Transfer Bytes |0 Transfer Packets|0 The command completed successfully. VPN Server/VPN_HUB>UserPasswordSet vpnuser UserPasswordSet command - Set Password Authentication for User Auth Type and Set Password Please enter the password. To cancel press the Ctrl+D key. Password: ******* Confirm input: ******* The command completed successfully.
ここでvpnuserのパスワードをメモしておきます
東京側でVPN接続を作成
VPN Server>hub VPN_HUB Hub command - Select Virtual Hub to Manage The Virtual Hub "VPN_HUB" has been selected. The command completed successfully. VPN Server/VPN_HUB>cascadecreate vpnconnection CascadeCreate command - Create New Cascade Connection Destination VPN Server Host Name and Port Number: 106.14.211.184:992 Destination Virtual Hub Name: VPN_HUB Connecting User Name: vpnuser The command completed successfully.
「接続」を作成完了したら、接続用のユーザ名とパスワードを設定します。このステップは先ほどメモしたパスワードを使います。
VPN Server/VPN_HUB>CascadeUsernameSet vpnconnection CascadeUsernameSet command - Set User Name to Use Connection of Cascade Connection Connecting User Name: vpnuser The command completed successfully. VPN Server/VPN_HUB>CascadePasswordSet vpnconnection CascadePasswordSet command - Set User Authentication Type of Cascade Connection to Password Authentication Please enter the password. To cancel press the Ctrl+D key. Password: ******* Confirm input: ******* Specify standard or radius: standard The command completed successfully.
両方のHUBでブリッジアダプターを作成 (東京・シンガポールの両方で実行)
VPN Server/VPN_HUB> BridgeCreate VPN_HUB /DEVICE:vpn /TAP:yes
VPN 接続を有効 (東京)。VPNのIP・静的ルートを設定
VPN Server/VPN_HUB> CascadeStatusGet vpn_connection CascadeStatusGet command - Get Current Cascade Connection Status Error occurred. (Error code: 29) Object not found. VPN Server/VPN_HUB>CascadeList CascadeList command - Get List of Cascade Connections Item |Value ----------------------+------------------------- Setting Name |vpnconnection Status |Online (Established) Established at |2017-07-06 (Thu) 14:15:55 Destination VPN Server|106.14.211.184 Virtual Hub |VPN_HUB The command completed successfully.
東京側
[ecs-user@iZ6we2zi66htonflydzqgmZ vpnserver]$ sudo ip add add 192.168.30.1/24 dev tap_vpn [ecs-user@iZ6we2zi66htonflydzqgmZ vpnserver]$ sudo ip route add 172.19.0.0/16 via 192.168.30.1 dev tap_vpn [ecs-user@iZ6we2zi66htonflydzqgmZ vpnserver]$ ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:16:3e:00:1b:ad brd ff:ff:ff:ff:ff:ff inet 10.2.219.148/16 brd 10.2.255.255 scope global eth0 valid_lft forever preferred_lft forever 8: tap_vpn: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:ac:ba:4a:a4:3e brd ff:ff:ff:ff:ff:ff inet 192.168.30.1/24 scope global tap_vpn valid_lft forever preferred_lft forever
シンガポール側
[ecs-user@izuf66a5gk8586mriekampz vpnserver]$ sudo ip add add 192.168.30.2/24 dev tap_vpn [ecs-user@izuf66a5gk8586mriekampz vpnserver]$ sudo ip route add 10.2.0.0/16 via 192.168.30.2 dev tap_vpn [ecs-user@izuf66a5gk8586mriekampz vpnserver]$ ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:16:3e:1c:33:e7 brd ff:ff:ff:ff:ff:ff inet 172.19.160.175/20 brd 172.19.175.255 scope global eth0 valid_lft forever preferred_lft forever 6: tap_vpn: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000 link/ether 00:ac:d2:d3:5f:88 brd ff:ff:ff:ff:ff:ff inet 192.168.30.2/24 scope global tap_vpn valid_lft forever preferred_lft forever
動作確認
ECSサーバーお互いのローカルIPをpingし、結果が戻ってくることを確認します。
## 東京 [ecs-user@iZ6we2zi66htonflydzqgmZ vpnserver]$ ping 172.19.160.175 PING 172.19.160.175 (172.19.160.175) 56(84) bytes of data. 64 bytes from 172.19.160.175: icmp_seq=1 ttl=64 time=119 ms 64 bytes from 172.19.160.175: icmp_seq=2 ttl=64 time=118 ms 64 bytes from 172.19.160.175: icmp_seq=3 ttl=64 time=125 ms ^C --- 172.19.160.175 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 118.251/121.104/125.359/3.079 ms ## シンガポール [ecs-user@izuf66a5gk8586mriekampz vpnserver]$ ping 10.2.219.148 PING 10.2.219.148 (10.2.219.148) 56(84) bytes of data. 64 bytes from 10.2.219.148: icmp_seq=1 ttl=64 time=136 ms 64 bytes from 10.2.219.148: icmp_seq=2 ttl=64 time=137 ms 64 bytes from 10.2.219.148: icmp_seq=3 ttl=64 time=129 ms 64 bytes from 10.2.219.148: icmp_seq=4 ttl=64 time=131 ms ^C --- 10.2.219.148 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3003ms rtt min/avg/max/mdev = 129.182/133.586/137.411/3.311 ms
これで、東京・シンガポールにあるECSサーバー間のVPN通信ができるようになりました。アプリケーションをこのECS上にデプロイしたら、シンガポールからでもVPN通信でアクセスできます。同じVSwitchにある他のサーバーを利用したければ、この2つのECSサーバーのIP転送を有効し、VRouterにルートを設定すれば通信ができます。
おわりに
SoftEtherにより東京・シンガポール間のVPN通信を実現する方法について書きました。いくつのコマンドを実行することで、既存の公共インターネット上でレイヤ2レベルで接続することができます。そして、同じクラウド内のリージョン間だけではなく、マルチクラウドのサーバー間やクラウド・オンプレミス間でVPN接続を構築可能です。当然ですが公共のインターネットなので、応答速度の不安定な場合があります。高いセキュリティーで高品質の接続を要求する場合は、是非 ExpressConnectをお試してください。
(Alibabaクラウドの日本リージョンでは夏ごろにExpressConnectがリリースされるので、ご期待ください)