ちょっと話題の記事

AWS Direct ConnectでPublic接続をやってみた

2020.10.29

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

はじめに

みなさん こんにちは。 はじめまして ネクストモード株式会社の柳です。

今年7月の会社設立と同時にインテグレーション事業部にJOINし、主にAWSのコンサル/設計構築/保守運用業務などに携わっています。得意なジャンルはネットワーク全般です。何よりも猫が好きなので、ペンネームはnekoです。

早速ですが、今回 AWS Direct Connect の Public接続環境を構築する機会がありましたので、ご紹介したいと思います。

ネットワーク構成

今回の接続構成は以下のようになっています。

  • 構成を補足しますと、拠点側回線はフレッツ光を使っていますが、今回はインターネットを利用しないシーンを想定しています(ISP網は通らずにNGNから直接AWSに接続する構成)
  • NGNからAWSに接続するために、NTT東日本の法人向けサービス「フレッツ・キャスト」を介して、EquinixのDCへ専用線にて接続しています。

作業の流れ

それでは早速、Public接続環境を作っていきましょう。 今回は AWS Direct Connect の物理接続は自前で引いており、既にPrivate Virtual Interfaceは構築済みのため、必要な作業は以下となります。

  1. Public接続用グローバルIPアドレスの用意
  2. Public Virtual Interfaceの作成
  3. オンプレBGPルータ用のサンプルコンフィグダウンロード
  4. ダウンロードしたコンフィグの修正とBGPルータへの投入
  5. AWS PublicサービスのDNS名前解決手段(経路)の確保
  6. 拠点側ルータ ⇔ BGPルータ間のトンネル接続用コンフィグの投入

Public接続用グローバルIPアドレスの用意

オンプレ側BGPルータとAWS側ルータ用に割り当てるグローバルIPを連番で2つ、用意します。 会社でグローバルIPを所持していて未使用のpoolがあれば、そちらを利用するのが一番楽でしょう。

Public Virtual Interfaceの作成

  1. AWSコンソールから サービス > Direct Connect > 仮想インターフェイス > 仮想インターフェースを作成する の順に選択し、Virtual Interfaceの作成画面に遷移します。
  2. 仮想インターフェースのタイプより「パブリック」を選択
  3. パブリック仮想インターフェイスの設定は、以下の値で設定します(アドレスは例です。実際使用した値とは異なります) ※「ルーターのピア IP」「Amazon ルーターのピア IP」「アドバタイズするプレフィックス」はご自身で用意したグローバルIPアドレスをそれぞれ指定してください。
  4. 問題がなければ、「仮想インターフェースを作成する」をクリックすると、仮想インターフェース一覧画面に戻りますので、作成したVIFの状態が「verifying」になり、AWS側への接続リクエスト承認待ちのステータスとなります。
  5. Public Virtual Interface作成後、AWS側よりリクエストが承認されると、VIFのステータスが「verifying」から「available」に変わります。 ※ AWS側で承認され、利用可能になるまでに最大で72時間ほどかかる場合があるそうです。参考

サンプルコンフィグのダウンロード

  1. AWSコンソールから サービス > Direct Connect > 仮想インターフェイス > 作成したVirtual Interface を選択します
  2. (ピアリングが複数ある場合は、ダウンロードしたいピアリングを選択し) アクション > ダウンロードする > サンプル設定 の順にクリックします
  3. ルータ設定としてご利用の機種に最も近い項目を選択し「ダウンロードする」をクリックします。 ※今回オンプレで使用するルータは「Cisco ASR-1001X, IOS XE 16.03」なので、「Cisco Systems inc, 7200 Series Routers, IOS 12.4+」を選択しました。

ダウンロードしたコンフィグの修正とBGPルータへの投入

ダウンロードしたコンフィグをそのままルータに投入しても、BGPは正常にUPしませんので、一度修正行程を挟みます。

ダウンロードしたコンフィグ

! Interface Configuration

! interface port-channel 1 (In case of a LAG connection)

interface GigabitEthernet0/1
! channel-group 1 mode passive (In case of a LAG connection)
  no ip address

interface GigabitEthernet0/1.4
! interface port-channel 1.4 (In case of a LAG connection)
  description "Direct Connect to your Amazon VPC or AWS Cloud"
  encapsulation dot1Q 4
  ip address 100.100.100.100 255.255.255.254

! Note: Please ensure to remove any individual member port configurations before the EtherChannel is configured.

! --------------------------------------------------------------------------------
! Border Gateway Protocol (BGP) Configuration
!
! BGP is used to exchange prefixes between the Direct Connect Router and your
! Customer Gateway.
!
! If this is a Private Virtual Interface, your Customer Gateway may announce a default route (0.0.0.0/0),
! which can be done with the 'network' and 'default-originate' statements. To advertise other/additional prefixes,
! copy the 'network' statement and identify the prefix you wish to advertise. Make sure the prefix is present in the routing
! table of the device with a valid next-hop.
!
! For Public Virtual Interface, you must advertise public IP prefixes that you own.
!
! The local BGP Autonomous System Number (ASN) (64817) is configured as
! part of your Customer Gateway. If the ASN must be changed, the Customer Gateway
! and Direct Connect Virtual Interface will need to be recreated with AWS.

router bgp 64817
  address-family ipv4
   neighbor 100.100.100.101 remote-as 7224
   neighbor 100.100.100.101 password xxxxxxxxxxxxxxxxx
   network " "  ! --> Prefixes you want to advertise over this Virtual Interface
exit

! --------------------------------------------------------------------------------
! Bidirectional Forwarding Detection (BFD) Configuration (Optional)
!
! Bidirectional Forwarding Detection (BFD) ensures fast forwarding-path failure detection times for BGP.
! Also provides fast failover to redundant Direct Connect connections.
! An example is provided below:
!

! interface GigabitEthernet0/1.4
!  bfd interval 300 min_rx 300 multiplier 3
! router bgp 64817
!  neighbor 100.100.100.101 fall-over bfd

! --------------------------------------------------------------------------------
! NAT Configuration for Public Virtual Interfaces (Optional)
! 
! If you don't have your own public ASN and prefix, you can request AWS to assign a /31 or /30 public prefix to you for BGP peering.
! In such case, you need to NAT all egress traffic through this virtual interface with the public VIF IP address on your side.
! 
! ip access-list standard NAT-ACL
!  permit any
! exit
! 
! ip nat inside source list NAT-ACL interface GigabitEthernet0/1.4 overload
! 
! interface GigabitEthernet0/1.4
!  ip nat outside
! exit
! 
! interface interface-towards-customer-local-network
!  ip nat inside
! exit

! --------------------------------------------------------------------------------
! Community Based Tagging/Filtering Configuration for Public Virtual Interfaces (Optional)
!
! You can use community tags on the prefixes you advertise to AWS to specify how far these prefixes will be propagated into Amazon network. 
! You can also build filters based on the community tags on Amazon routes being received.
!
!                     To advertise to AWS    Prefixes from AWS
! LOCAL-AWS-REGION    7224:9100              7224:8100
! LOCAL-CONTINENT     7224:9200              7224:8200
! GLOBAL              7224:9300              No tag
!
! Please add the appropriate community tag when advertising prefixes to Amazon using the following example:
!
! ip bgp-community new-format
! ip prefix-list TAG-TO-AWS permit 0.0.0.0/0 le 32
! route-map TO-AWS permit 10
!  match ip address prefix-list TAG-TO-AWS 
!  set community 7224:9100
! router bgp 64817
!  address-family ipv4
!   neighbor 100.100.100.101 send-community
!   neighbor 100.100.100.101 route-map TO-AWS out
!
! Please use the appropriate community tag to filter (Permit or Deny) prefixes from Amazon using the following example:
!
! ip bgp-community new-format
! ip community-list standard COMM-FROM-AWS permit 7224:8100
! route-map FROM-AWS permit 10
!  match community COMM-FROM-AWS
! router bgp 64817
!  address-family ipv4 
!   neighbor 100.100.100.101 route-map FROM-AWS in

※グローバルアドレス記述部分は例として編集しています

修正後のコンフィグ

! vrf Configuration
!
vrf definition VRF0004
 rd 64817:4
 !
 address-family ipv4
  route-target export 64817:4
  route-target import 64817:2
 exit-address-family
 !
 address-family ipv6
 exit-address-family
!
! Interface Configuration
!
interface GigabitEthernet0/0/4.4
 description "Direct Connect to AWS Public Cloud"
 encapsulation dot1Q 4
 vrf forwarding VRF0004
 ip nat outside
 ip address 100.100.100.100 255.255.255.254
exit
!
interface Tunnel4
 description "To Yamaha_RTX1200"
 vrf forwarding VRF0004
 ip nat inside
!
! Border Gateway Protocol (BGP) Configuration
!
ip prefix-list vlan4-dx seq 5 permit 100.100.100.100/31
!
route-map VLAN4-out permit 10
 match ip address prefix-list vlan4-dx
!
router bgp 64817
 address-family ipv4 vrf VRF0004
  network 100.100.100.100 mask 255.255.255.254
  neighbor 100.100.100.101 remote-as 7224
  neighbor 100.100.100.101 password xxxxxxxxxxxxxxxxx
  neighbor 100.100.100.101 activate
  neighbor 100.100.100.101 route-map VLAN4-out out
 exit-address-family
exit
!
! NAT Configuration for Public Virtual Interfaces
! 
ip access-list standard NAT-ACL
 permit 10.0.0.0 0.255.255.255
 permit 172.16.0.0 0.15.255.255
 permit 192.168.0.0 0.0.255.255
exit
! 
ip nat inside source list NAT-ACL interface GigabitEthernet0/4.4 vrf VRF0004 overload
!
! Discard high-risk packets arriving via public Virtual Interface
!
ip access-list extended DX-Public-VLAN-0004-In
 permit ip 100.100.100.100 0.0.0.1 100.100.100.100 0.0.0.1
 deny tcp any any eq 22
 deny tcp any any eq telnet
 deny tcp any any eq www
 deny tcp any any eq 443
 permit ip any any
exit
!
interface GigabitEthernet0/0/4.4
 ip access-group DX-Public-VLAN-0004-In in
  • 補足事項
    • bgp-community, Port-Channel, LAGは今回の構成では不要としています。
    • BFDも別途ip slaで代用するため、同様に不要としました。
    • AWS向けvlan-IFと後述する拠点ルータ(rtx1200)向けTunnel-IFはVRFを使うため、VFR0004として定義しています(VRFが不要の場合は該当コンフィグは必要ありません)
  • 注意点
    • 忘れがちですが、ルータにグローバルIPを付与することになるので、AWS側からのセキュリティリスクが高い通信は、全てACLで遮断しましょう。
    • VRFを使う場合は、サンプルコンフィグのソースNAT指定の行を以下のようにvlanが所属するVRFを明示的に指定してください。
    • Public接続を利用する上で、プライベートIP → グローバルIPへのNAT変換は必須ですが、サンプルコンフィグのNAT ACLのままでは、自発を含めたBGPパケットもNAT対象となるためか、正常にBGPがUPしないことがありました。 そのため、以下のようにNAT対象をプライベートアドレスのみに限定しました。
(修正前)

! source nat
ip nat inside source list NAT-ACL interface GigabitEthernet0/1.4 overload

! NAT-ACL
 ip access-list standard NAT-ACL
  permit any
(修正後)

! source nat
ip nat inside source list NAT-ACL interface GigabitEthernet0/4.4 vrf VRF0004 overload

! NAT-ACL
ip access-list standard NAT-ACL
 permit 10.0.0.0 0.255.255.255
 permit 172.16.0.0 0.15.255.255
 permit 192.168.0.0 0.0.255.255

AWS PublicサービスのDNS名前解決手段(経路)の確保

AWSのPublicサービスを利用するにあたり、通常DNSによるエンドポイントの名前解決が必要ですが、今回の構成ではインターネットに繋がっていない環境のため、別途名前解決手段(経路)を用意する必要があります。

Direct Connect Public接続のみの環境ですと、AWSからBGPで通知されるルーティング情報にはDNSサーバのアドレスは含まれておらず、別途EIPを付与したEC2をDNSキャッシュサーバとして設置する等の工夫が必要ですが、今回は幸いにもDirect Connect Private接続環境があるため、そちらにDirectory Service(Simple AD)を立てて、オンプレ環境からのDNS問い合わせ先に指定しました。 Simple ADの構築手順は こちらをご参照ください。

Simple ADを構築したら、割り当てられたDNSアドレスを控えておいてください。

拠点側ルータ ⇔ BGPルータ間のトンネル接続用コンフィグの投入

拠点ルータ⇔BGPルータ間は、フレッツ光回線 → NGN → フレッツ・キャストを通っており、通常NGNはPPPoE以外のパケットはIPv6のみ通信可能となりますので、IPv4で通信をしたい場合は、ルータ間でなんらかのカプセル化を行う必要があります。今回はシンプルにIPIP Tunnel(IPv6カプセル化)を利用します。

  • BGPルータ(Cisco ASR-1001X) コンフィグ例
interface Tunnel4
 description "To Yamaha_RTX1200"
 vrf forwarding VRF0004
 ip unnumbered GigabitEthernet0/0/4.4 # Public-VIF接続vlanのアドレスをunnumberedで指定
 no ip redirects
 ip nat inside
 ip tcp adjust-mss 1420
 keepalive 10 3
 tunnel source GigabitEthernet0/0/0   # NGN側IFを指定
 tunnel mode ipv6
 tunnel destination 2001:db8::2       # YamahaルータのWAN側IPv6アドレスを指定
 tunnel path-mtu-discovery
!
ip route vrf VRF0004 192.168.1.0 255.255.255.0 Tunnel4
  • 拠点ルータ(Yamaha RTX1200) コンフィグ例
ip route default gateway 100.100.100.100 tunnel 1
!
ipv6 prefix 1 ra-prefix@lan2::/64
ip lan1 address 192.168.1.1/24
ipv6 lan1 address ra-prefix@lan2::1/64
ipv6 lan1 rtadv send 1 o_flag=on
ipv6 lan1 dhcp service server
ipv6 lan2 dhcp service client ir=on
!
tunnel select 1
 tunnel encapsulation ipip
 tunnel endpoint address 2001:db8::1  # BGPルータ(cisco) TunnelソースIF(Gi0/0/0)のIPv6アドレスを指定
 ip tunnel mtu 1460
 ip tunnel tcp mss limit auto
 tunnel enable 1
!
dhcp service server
dhcp server rfc2131 compliant except remain-silent
dhcp scope 1 192.168.1.2-192.168.1.191/24
dns host lan1
dns server 172.16.1.14 172.16.1.30    # Simpe ADのDNSアドレスを指定
dns private address spoof on

以上の設定をルータに投入すれば、接続準備は完了です。

動作確認

  • BGPルータのBGPステータスとルーティング情報の確認

無事BGPが繋がりました。AWS側から広告された経路数が凄いことになっています(3960 subnet!!)

  • 拠点PCよりFQDN指定でのAWS Publicサービスへの疎通確認

インターネットに繋がっていない環境でも、FQDN指定でAWS Publicサービスに接続できました。

まとめ

今回は検証環境の構築ということでネットワークはシングル構成でしたが、商用環境を想定したルータの冗長化や拠点ルータのBGP化など実施する機会がありましたら、次の機会にご紹介したいと思います。