AWS VPC VPN ConnectionsがNAT Traversal対応したので試してみた

2015.11.08

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、コカ・コーラが大好きなカジです。

下記ブログでAWS VPC VPN ConnectionsがNAT Traversal(NAT-T)に対応したことが発表されたので、VyOSを使ってNATルータ経由し、動的ルーティングでAWSとVPN接続をしてみましたので紹介します。(まあ、簡単に言うと自宅とAWSを動的ルーティングVPN接続しました。)

EC2 VPC VPN Update – NAT Traversal, Additional Encryption Options, and More

NAT Traversalについての詳細は、Wikipediaここを参照ください。

構成図

kaji-vpc-vpn-nat-t-01

AWS側

以前のVPN Connectionsの設定と全く変更ありません。

Virtual Private Gatewayを構築

VGWとVPCへのアタッチも忘れずに。 kaji-vpc-vpn-nat-t-02

カスタマーゲートウェイを登録

NATルータのグローバルIPアドレスを調査して下のIPアドレスに入力しましょう。 kaji-vpc-vpn-nat-t-03

VPN Conectionsの設定

kaji-vpc-vpn-nat-t-04

Configファイルもダウンロードします。 kaji-vpc-vpn-nat-t-05

オンプレミス側

ブロードバンドルータ(NATルータ)

NAT Traversalで必要な、UDP500とUDP4500を開放し、VPNルータ(VyOS)へ通信するよう設定します。

私の自宅はYAMAHAルータだったので、以下のような設定になります。

[トップ] > [詳細設定と情報] > [基本接続の詳細な設定] > [プロバイダの修正(PP[01])]

kaji-vpc-vpn-nat-t-06

VPNルータ

AWS VPC VPN Connectionsに対応しているVPNルータに制限がありますのでご注意ください。AWSにて検証されている機器についてはAmazon VPCのよくある質問の「Q:Amazon VPC で機能することが知られているカスタマーゲートウェイ装置にはどのようなものがありますか?」という項目に記載されています。

上記に記載されている別なネットワーク機器がありましたら、試してみると面白いと思います。 手軽に行うには、古いPCなどにVyOSをインストールしルータを構築しても良いですし、ハイパーバイザー上でも良いと思います。 私は、VMware vSphere Hypervisor(ESXi)上にVyOSを利用して構築しました。

検証環境

  • VMware vSphere Hypervisor(ESXi) 6.0 2494585
  • [VyOS 1.1.6](http://mirror.vyos.net/iso/release/1.1.6/vyos-1.1.6-amd64.iso)
  • 1vCPU/2GB/18GB (Debian GNU/Linux6 64bitの設定のまま)
  • 仮想NICを1つ追加して、2個にしてシンプルな構成で構築します。

基本的な構築方法は、VyOSユーザーガイドを参照しましょう。

デフォルトログイン

初期ユーザ名:vyos
初期パスワード:vyos

各インターフェイスのIPアドレスとデフォルトゲートウェイ設定

set interfaces ethernet eth0 address 192.168.1.12/24
set interfaces ethernet eth0 description OutSide
set interfaces ethernet eth1 address 172.16.1.1/24
set interfaces ethernet eth0 description InSide
set system gateway-address 192.168.1.1

VyOSのssh許可設定

set service ssh listen-address 192.168.1.12
set service ssh listen-address 172.16.1.1
set service ssh port 22

日本時刻設定

set system time-zone Asia/Tokyo

VPN利用インターフェイス指定とNAT Traversal設定

set vpn ipsec nat-traversal enable
set vpn ipsec ipsec-interfaces interface eth0
set vpn ipsec nat-networks allowed-network 0.0.0.0/0

AWSの自動出力Configを流し込む

AWS VPC VPN Connectionsで出力されたConfigを投入します。

2つのVPN Tunnelのlocal-addressをVyOSのeth0のアドレスへ修正

set vpn ipsec site-to-site peer xxx.xxx.76.184 local-address 192.168.1.12
set vpn ipsec site-to-site peer xxx.xxx.98.6 local-address 192.168.1.12

VPN IPsecプロセスの再起動

sudo /etc /init.d/ipsec restart

VyOSでAWSと接続中のステータス

vyos@vyos:~$ show interface
Codes: S - State, L - Link, u - Up, D - Down, A - Admin Down
Interface IP Address S/L Description
--------- ---------- --- -----------
eth0 192.168.1.12/24 u/u OutSide
eth1 172.16.1.1/24 u/u InSide
lo 127.0.0.1/8 u/u
::1/128
vti0 169.254.25.130/30 u/u VPC tunnel 1
vti1 169.254.24.62/30 u/u VPC tunnel 2
vyos@vyos:~$ show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
I - ISIS, B - BGP, > - selected route, * - FIB route

S>* 0.0.0.0/0 [1/0] via 192.168.1.1, eth0
B>* 10.10.0.0/16 [20/100] via 169.254.25.129, vti0, 00:22:41
C>* 127.0.0.0/8 is directly connected, lo
C>* 169.254.24.60/30 is directly connected, vti1
C>* 169.254.25.128/30 is directly connected, vti0
C>* 172.16.1.0/24 is directly connected, eth1
C>* 192.168.1.0/24 is directly connected, eth0
vyos@vyos:~$
vyos@vyos:~$ show vpn ipsec sa
Peer ID / IP Local ID / IP
------------ -------------
xxx.xxx.76.184 192.168.1.12

Description: VPC tunnel 1

Tunnel State Bytes Out/In Encrypt Hash NAT-T A-Time L-Time Proto
------ ----- ------------- ------- ---- ----- ------ ------ -----
vti up 2.3K/1.5K aes128 sha1 yes 1127 3600 all

Peer ID / IP Local ID / IP
------------ -------------
xxx.xxx.98.6 192.168.1.12

Description: VPC tunnel 2

Tunnel State Bytes Out/In Encrypt Hash NAT-T A-Time L-Time Proto
------ ----- ------------- ------- ---- ----- ------ ------ -----
vti up 32.3K/24.5K aes128 sha1 yes 3246 3600 all

vyos@vyos:~$

PCからの通信確認

% ifconfig en4
en4: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=3<RXCSUM,TXCSUM>
<省略>
inet 172.16.1.2 netmask 0xffffff00 broadcast 172.16.1.255
nd6 options=1 media: autoselect (1000baseT <full-duplex,flow-control>)
status: active
%
% netstat -rn -f inet
Routing tables

Internet:
Destination Gateway Flags Refs Use Netif Expire
default 172.16.1.1 UGSc 8 11 en4
127 127.0.0.1 UCS 2 39 lo0
127.0.0.1 127.0.0.1 UH 6 2159 lo0
127.0.53.53 127.0.0.1 UHWIi 1 1 lo0
169.254 link#4 UCS 1 0 en4
172.16.1/24 link#4 UCS 2 0 en4
172.16.1.1/32 link#4 UCS 2 0 en4
172.16.1.1 0:c:29:17:cc:d4 UHLWIir 8 0 en4 1177
172.16.1.2/32 link#4 UCS 1 0 en4
172.16.1.255 ff:ff:ff:ff:ff:ff UHLWbI 1 6 en4
%
% ping 10.10.10.226
PING 10.10.10.226 (10.10.10.226): 56 data bytes
64 bytes from 10.10.10.226: icmp_seq=0 ttl=62 time=32.435 ms
64 bytes from 10.10.10.226: icmp_seq=1 ttl=62 time=37.461 ms
64 bytes from 10.10.10.226: icmp_seq=2 ttl=62 time=32.347 ms
64 bytes from 10.10.10.226: icmp_seq=3 ttl=62 time=32.625 ms
^C
--- 10.10.10.226 ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 32.347/33.717/37.461/2.164 ms
% ssh -i aws.pem ec2-user@10.10.10.226
Last login: Sun Nov 8 01:22:27 2015 from ip-172-16-1-2.ap-northeast-1.compute.internal

__| __|_ )
_| ( / Amazon Linux AMI
___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2015.03-release-notes/
46 package(s) needed for security, out of 126 available
Run "sudo yum update" to apply all updates.
Amazon Linux version 2015.09 is available.
[ec2-user@ip-10-10-10-226 ~]$
[ec2-user@ip-10-10-10-226 ~]$
[ec2-user@ip-10-10-10-226 ~]$
[ec2-user@ip-10-10-10-226 ~]$ exit
logout
Connection to 10.10.10.226 closed.
%

VyOSのConfig

vyos@vyos:~$ show config
interfaces {
ethernet eth0 {
address 192.168.1.12/24
description OutSide
duplex auto
hw-id 00:0c:29:17:cc:ca
smp_affinity auto
speed auto
}
ethernet eth1 {
address 172.16.1.1/24
description InSide
duplex auto
hw-id 00:0c:29:17:cc:d4
smp_affinity auto
speed auto
}
loopback lo {
}
vti vti0 {
address 169.254.25.130/30
description "VPC tunnel 1"
mtu 1436
}
vti vti1 {
address 169.254.24.62/30
description "VPC tunnel 2"
mtu 1436
}
}
protocols {
bgp 65000 {
neighbor 169.254.24.61 {
remote-as 10124
soft-reconfiguration {
inbound
}
timers {
holdtime 30
keepalive 30
}
}
neighbor 169.254.25.129 {
remote-as 10124
soft-reconfiguration {
inbound
}
timers {
holdtime 30
keepalive 30
}
}
network 0.0.0.0/0 {
}
}
}
service {
ssh {
listen-address 192.168.1.12
listen-address 172.16.1.1
port 22
}
}
system {
config-management {
commit-revisions 20
}
console {
device ttyS0 {
speed 9600
}
}
gateway-address 192.168.1.1
host-name vyos
login {
user vyos {
authentication {
encrypted-password ****************
plaintext-password ****************
}
level admin
}
}
ntp {
server 0.pool.ntp.org {
}
server 1.pool.ntp.org {
}
server 2.pool.ntp.org {
}
}
package {
auto-sync 1
repository community {
components main
distribution helium
password ****************
url http://packages.vyos.net/vyos
username ""
}
}
syslog {
global {
facility all {
level notice
}
facility protocols {
level debug
}
}
}
time-zone Asia/Tokyo
}
vpn {
ipsec {
esp-group AWS {
compression disable
lifetime 3600
mode tunnel
pfs enable
proposal 1 {
encryption aes128
hash sha1
}
}
ike-group AWS {
dead-peer-detection {
action restart
interval 15
timeout 30
}
lifetime 28800
proposal 1 {
dh-group 2
encryption aes128
hash sha1
}
}
ipsec-interfaces {
interface eth0
}
nat-networks {
allowed-network 0.0.0.0/0 {
}
}
nat-traversal enable
site-to-site {
peer xxx.xxx.76.184 {
authentication {
mode pre-shared-secret
pre-shared-secret ****************
}
description "VPC tunnel 1"
ike-group AWS
local-address 192.168.1.12
vti {
bind vti0
esp-group AWS
}
}
peer xxx.xxx.98.6 {
authentication {
mode pre-shared-secret
pre-shared-secret ****************
}
description "VPC tunnel 2"
ike-group AWS
local-address 192.168.1.12
vti {
bind vti1
esp-group AWS
}
}
}
}
}
vyos@vyos:~$

まとめ

以前は、NATルータを経由したVPN接続ができなかったため、VPNルータの配置場所が限られましたが柔軟性が増しました。 どなたかのお役に立てれば光栄です。