LoginSignup
2
2

More than 3 years have passed since last update.

SiteToSiteVPNを同一リージョン内で構築した方法

Posted at

概要

  • Site-to-Site VPN 接続による外部ネットワークとの接続環境を構築するため、VPC間でどのように設定する必要があるのか、検証するために構築した環境について
  • Customer Gateway側のルータには VyOS を使用

対象

  • オンプレミスネットワーク等とのVPN接続環境を構築することになったけど、どういう構造になるのかAWSのみで構築し、確認してみたい。という方。

構成

構成

環境構築のポイント

環境構築については、SiteToSiteVpnDemoのREADMEを参照してください。

以下は、CloudFormationでポイントとなると思われる箇所について抜粋しています。

VyOS

  • CoustomerGateway側のルータにはVyOSを使用しています。
  • 有償版(フリートライアルあり)のAMIを利用しているので、CloudFormationでの構築時にエラーが発生します。
  • エラー内容に掛かれたURLへ移動し、VyOSのAMI利用に対してSubscribeして下さい。

ルートテーブル

  • それぞれのルートテーブルに、別のVPCへルーティングするための設定が必要です。
  • 10.38.0.0/24 のサブネットを紐づけているルートテーブルでは、宛先が 10.39.0.0/16 の場合には、VPN Gateway へルーティングするように設定しています。
template.yml
  AwsRoute2:
    Type: AWS::EC2::Route
    Properties:
      GatewayId: !Ref VPNGateway
      DestinationCidrBlock: 10.39.0.0/16
      RouteTableId: !Ref AwsRouteTable
    DependsOn: VPCGatewayAttachment
  • 10.39.0.0/24 のサブネットを紐づけているルートテーブルでは、宛先が 10.38.0.0/16 の場合には、ルータ(VyOS)のインスタンスへルーティングするように設定しています。
template.yml
  CustomerRoute2:
    Type: AWS::EC2::Route
    Properties:
      InstanceId: !Ref VyOSInstance
      DestinationCidrBlock: 10.38.0.0/16
      RouteTableId: !Ref CustomerRouteTable

セキュリティグループ

  • それぞれ疎通確認に ping を利用します。お互いに接続先のプライベートIPアドレスCIDRを許可するように指定(サンプルでは全て通すように設定していますが、必要最小限の設定は以下の FromPort / ToPort で指定)
tempalte.yaml
  AwsSiteSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupName: AwsSiteSecurityGroup
      GroupDescription: AwsSiteSecurityGroup
      SecurityGroupIngress:
      - IpProtocol: -1
        FromPort: 0
        ToPort: 65535
        CidrIp: 10.39.0.0/16
        Description: CustomerSite Private IP
...
  CustomerSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupName: CustomerSiteSecurityGroup
      GroupDescription: CustomerSiteSecurityGroup
      SecurityGroupIngress:
      - IpProtocol: -1
        FromPort: 0
        ToPort: 65535
        CidrIp: 10.38.0.0/16
        Description: AwsSite Private IP

Site-to-Site VPN

  • CustomerGatewayでは、IPアドレスにルータ(VyOS)に指定したEIPを設定。VPN接続のタイプは ipsec.1
  • VPNGatewayにもVPN接続のタイプに ipsec.1。10.38.0.0/16 側のVPCにアタッチ
  • VPN ConnectionでもVPN接続タイプを指定(ipsec.1)。ここでCustomerGatewayと、VPNGatewayを紐づける。
template.yml
  CustomerGateway:
    Type: AWS::EC2::CustomerGateway
    Properties:
      BgpAsn: 65000
      IpAddress: !Ref VyOSEIP
      Type: ipsec.1
  VPNGateway:
    Type: AWS::EC2::VPNGateway
    Properties:
      Type: ipsec.1
  VPCGatewayAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref Vpc
      VpnGatewayId: !Ref VPNGateway
  VPNConnection:
    Type: AWS::EC2::VPNConnection
    Properties:
      Type: ipsec.1
      CustomerGatewayId: !Ref CustomerGateway
      VpnGatewayId: !Ref VPNGateway

VyOSの設定

CloudFormationで環境が構築されたら、VyOSの設定が必要になります。
VPN Connectionのページから、設定をダウンロードできます。
VyOSの設定をダウンロードするのですが、VendorはVyattaを指定してください。
但し、ローカルIPアドレスの設定変更と、現時点でAWSからダウンロードできる設定と、上記で構築したVyOSのバージョン(1.2.3)での差分があるので、そちらを反映させる必要があります。

set vpn ipsec site-to-site peer xx.xx.xx.xx local-address

  • xx.xx.xx.xxにはVPN ConnectionのトンネルのOutsite IP Addressが入ります。
  • トンネルは2つ構成となっているので、2か所修正する必要があります。
  • ダウンロードした設定ファイルでは、local-addressがVyOSのパブリックIPアドレスになっているため、プライベートIPアドレスに変更します。
set vpn ipsec site-to-site peer *.*.*.* local-address '54.250.169.14'
↓
set vpn ipsec site-to-site peer *.*.*.* local-address '10.39.0.30'

set protocols bgp 65000 neighbor xx.xx.xx.xx soft-reconfiguration 'inbound'

  • もとのまま投入すると構文エラーになります。
  • 以下のように修正します。
set protocols bgp 65000 neighbor *.*.*.* soft-reconfiguration 'inbound'
↓
set protocols bgp 65000 neighbor *.*.*.* address-family ipv4-unicast soft-reconfiguration 'inbound'

set protocols bgp 65000 network xx.xx.xx.xx/xx

  • もとのまま投入すると構文エラーになります。
  • 以下のように修正します。
set protocols bgp 65000 network *.*.*.*/*
↓
set protocols bgp 65000 address-family ipv4-unicast network *.*.*.*/*

設定の修正が完了したら、VyOSのインスタンスへログインし、設定ファイルを流し込んでく下さい。
インスタンスへのログインと設定の反映については、SiteToSiteVpnDemoのREADMEを参照してください。

さいごに

  • 上記設定まで完了すれば、VPN Connectionのページのトンネルの詳細で、トンネルのステータスがUPされていることが確認できると思います。
  • あとは、それぞれのインスタンスへ接続し、互いのVPCのインスタンスに対してローカルIPアドレスで接続出来ることが出来ると思いますので、あとは自身の試してみたい構成などに拡張していけば宜しいかと。
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2