Amazon EC2(Vyatta)からAmazon VPCに接続してみた

Amazon EC2(Vyatta)からAmazon VPCに接続してみた
「さくらのVPSにVyattaを入れて、Amazon VPCにVPN接続」を見て、EC2でもつないでみようと思い立った。

準備

AMIはVyattaのAMIを使いました。インスタンスタイプはt1.micro。
ネットワーク構成はこんな感じ。

基本的なconfigはid:iamsandmanさんのページを参考にして作成したが、EC2で動かすにあたって一部変更が必要だった。

  • NAT環境なので、eth0はプライベートアドレス(dhcp)となる。IPsecやlocal側のサブネット用のアドレスはloopbackにとりあえず振ってみた。
interfaces {
    loopback lo {
        address 169.254.255.2/32
        address 169.254.255.6/32
        address 172.22.0.1/16
    }
}
  • IPsecのlocal-ipに指定するアドレスはeth0のアドレスなので、起動しないとわからない。これは自動化するにはちょっと面倒。
  • 接続後にルーティング情報をupdateするスクリプトを走らせる必要があるのは同様。
  • VPC側のRoute Tableには以下のように戻りのgatewayを指定しておく必要がある
172.21.0.0/16 local
172.22.0.0/16 vgw-xxxxxxxx

できあがったコンフィグはこちら。接続用のスクリプトこちら

設定の投入(追記しました)

$ configure
# merge /home/vyatta/merge.txt
# exit
$ ./connect.sh

動作確認

vyatta@vyatta:~$ ping  169.254.255.1
PING 169.254.255.1 (169.254.255.1) 56(84) bytes of data.
64 bytes from 169.254.255.1: icmp_seq=1 ttl=64 time=187 ms
64 bytes from 169.254.255.1: icmp_seq=2 ttl=64 time=187 ms
64 bytes from 169.254.255.1: icmp_seq=3 ttl=64 time=187 ms
64 bytes from 169.254.255.1: icmp_seq=4 ttl=64 time=187 ms
^C
--- 169.254.255.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3011ms
rtt min/avg/max/mdev = 187.697/187.765/187.852/0.311 ms
vyatta@vyatta:~$ ping 169.254.255.5
PING 169.254.255.5 (169.254.255.5) 56(84) bytes of data.
64 bytes from 169.254.255.5: icmp_seq=1 ttl=64 time=203 ms
64 bytes from 169.254.255.5: icmp_seq=2 ttl=64 time=203 ms
64 bytes from 169.254.255.5: icmp_seq=3 ttl=64 time=210 ms
64 bytes from 169.254.255.5: icmp_seq=4 ttl=64 time=204 ms
^C
--- 169.254.255.5 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3010ms
rtt min/avg/max/mdev = 203.984/205.548/210.047/2.637 ms
vyatta@vyatta:~$ ping 172.21.0.4
PING 172.21.0.4 (172.21.0.4) 56(84) bytes of data.
64 bytes from 172.21.0.4: icmp_seq=1 ttl=62 time=188 ms
64 bytes from 172.21.0.4: icmp_seq=2 ttl=62 time=188 ms
64 bytes from 172.21.0.4: icmp_seq=3 ttl=62 time=188 ms
64 bytes from 172.21.0.4: icmp_seq=4 ttl=62 time=188 ms
^C
--- 172.21.0.4 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3010ms
rtt min/avg/max/mdev = 188.238/188.360/188.489/0.541 ms
vyatta@vyatta:~$ ssh -i j3tm0t0.pem ec2-user@172.21.0.4
Last login: Mon May  2 04:11:00 2011 from 172.22.0.1

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

See /usr/share/doc/system-release-2011.02 for latest release notes. :-)
[ec2-user@ip-172-21-0-4 ~]$ w
 04:12:38 up 15:29,  1 user,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
ec2-user pts/0    172.22.0.1       04:12    0.00s  0.00s  0.00s w
[ec2-user@ip-172-21-0-4 ~]$ ssh -i j3tm0t0.pem vyatta@172.22.0.1
Welcome to Vyatta
Linux vyatta 2.6.35.4 #1 SMP Wed Nov 3 13:16:47 EDT 2010 i686
Welcome to Vyatta.
This system is open-source software. The exact distribution terms for 
each module comprising the full system are described in the individual 
files in /usr/share/doc/*/copyright.
Last login: Mon May  2 04:13:22 2011 from ip-172-21-0-4.ap-northeast-1.compute.internal
vyatta@vyatta:~$ 

というわけで、pingsshも通っていた。

TODO