Oracle Cloud: Cisco 841M ルーターを IKEv2 と BGPで IPSec VPN接続してみてみた

[前回設定した Cisco ルーター 841M](https://qiita.com/shirok/items/ec430ab16111193ac587) を使用して、Oracle Cloud Infrastructure (OCI) へ Site-to-Site VPN (IPSec) を IKEv2 (Internet Key Exchange version 2) と BGP（Border Gateway Protocol）を使用して接続してみてみます。
また、2本のTunnelの非対称ルーティングを避けるため、Tunnel1 を優先経路とするよう、AS Path PrependでBGP経路制御してみます。

# ■ 構成図
![構成.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/4f879c13-da1b-0901-9aec-567a90f5f873.jpeg)
IPSec VPN Connection を作成すると、冗長用途でVPN接続は2つの IPSecトンネルで構成され、各トンネル異なるOracleルーターに自動的にプロビジョニングされます。そのためCISCOルーターに２つの IPSec Tunnelを構成します。

## ● 設定値
ルーターの設定は、CISCO社により検証されたコンフィグを参考として使用します。
　・参考: [CPE Configuration: Cisco IOS](https://docs.oracle.com/en-us/iaas/Content/Network/Reference/ciscoiosCPE.htm)
パラメーターは、構成図を参考にRouterへ設定する値を表にしておきます

|パラメーター  |値  |説明  |
|---|---|---|
|${bgpASN} |65000| CPE BGP ASN|
|${cpeInsideTunnelIpAddress1}|192.168.254.101/30|Inside tunnel IP address of CPE for the first tunnel. |
|${cpeInsideTunnelIpAddress2}|192.168.254.102/30|Inside tunnel IP address of CPE for the second tunnel. |
|${OracleInsideTunnelIpAddress1} |192.168.254.102/30| Inside tunnel IP address of Oracle-side for the first tunnel. |
|${OracleInsideTunnelIpAddress2} |192.168.254.106/30| Inside tunnel IP address of Oracle-side for the second tunnel. |
|${cpePublicIpAddress} |100.100.100.101| The public IP address for the CPE.|
|${oracleHeadend1} |140.204.100.101| Oracle public IP endpoint obtained from the Oracle Console.|
|${oracleHeadend2} |140.204.100.102| Oracle public IP endpoint obtained from the Oracle Console.|
|${sharedSecret1} |password| first tunnel SharedSecret|
|${sharedSecret2} |password| second tunnel SharedSecret|
|${onPremCidrNetwork} |192.168.0.0| On-premises IP range|
|${onPremCidrNetmask} |255.255.255.0| ON-premises subnet mask|

# ■ OCI事前準備
VCN、Compute等、事前に設定しておきます。今回は、DRG,IPSec Connectionの設定して疎通確認します。


# ■ Dynamic Routing Gateways (DRG)作成
1) OCIコンソール
Networking > Dynamic Routing Gateways を選択
![02_DRG作成00.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/aeac35b9-f81e-6bc6-b5f6-b164f1938b2d.jpeg)



2) Dynamic Routing Gateways画面
[Create Dynamic Routing Gateway]をクリック
![02_DRG作成01.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/6848f116-72c7-bf57-aea9-010cd5d50bb5.jpeg)

3) Dynamic Routing Gatewaysの作成画面
以下項目を設定し、[Create Dynamic Routing Gateway]をクリックして作成

	・Name: 任意の名前

![02_DRG作成02.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/16b5cbfd-af27-33e4-5485-dba2a8b2998e.jpeg)

4) DRG作成完了
![02_DRG作成03.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/931e96fc-610f-86eb-25db-7a6196d8d319.jpeg)


# ■ VCN - DRG接続
作成したDRGへVCNをAttachします

1) DRG: Virtual Cloud Networks Attachments画面
作成したDRG画面 > Resources > Virtual Cloud Networks Attachmentsをクリックし、
[Virtual Cloud Networks Attachments]をクリック
![03_DRG-VCN-Attachment作成00.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/f8ecec6f-bf2f-0a29-9cf7-5abd135882b7.jpeg)




2) Create Virtual Cloud Network Attachment画面
以下項目を設定し、[Create Virtual Cloud Network Attachment]をクリックして作成

・Attachment name: 任意の名前

![03_DRG-VCN-Attachment作成01.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/6a964d0a-5707-56e6-b5fc-d52f67249f9c.jpeg)

3) VCN Attach完了
![03_DRG-VCN-Attachment作成03.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/c45a4fa3-3503-8655-1271-788ca56e3c6d.jpeg)


# ■ CPE Object(顧客構内機器)作成
1) OCIコンソール
Networking > Customer-Premises Equipment を選択
![04_CPE作成01.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/c6e7c1c8-92d0-7abb-d4ba-3107943f7f8d.png)


2) Customer-Premises Equipment画面
[Create Customer-Premises Equipment]をクリック
![04_CPE作成02.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/1f0a3ce4-65a1-87f0-a2c6-cda7f5211233.jpeg)


3) Create Customer-Premises Equipment画面
以下入力を行い、[Create CPE]をクリックして作成

	・Name: 任意の名前
	・Public IP Address: CPEの Public IP Address
	・Vendor: CPE Vendorを選択
	・Platform/Version: CPE Versionを選択

![04_CPE作成03.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/db76832e-e418-96a7-b875-c4d932b22fb2.jpeg)


4) CPE Object作成完了
![04_CPE作成04.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/7ac0f605-6f4f-beab-d735-5607a0de3ae6.jpeg)


# ■ IPSec Connection作成
1) OCIコンソール
Networking > Site-to-Site VPN (IPSec) を選択
![05_IPSec作成01.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/21efb14b-fb2d-3e6e-185f-766ef5ef4722.jpeg)



2) Site-to-Site VPN (IPSec)画面
[Create IPSec Connection]をクリック
![05_IPSec作成02.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/2484dc77-592b-05a2-cdb3-57f7d3225ca8.jpeg)



3) Create IPSec Connection画面
以下入力を行い、[Create IPSec Connection]をクリックして作成

・ IPSec情報

	・Name: 任意の名前
	・Customer-Premises Equipment: 作成した CPE Objectを設定
	・Dynamic Routing Gateway Compartment: 作成した DRGを設定

![05_IPSec作成03.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/078f6264-ce27-6e08-9aac-607e383b18d1.jpeg)

・ Tunnel1 BGP 情報

	・Name: 任意の名前
	・Shared Secret: 作成した CPE Objectを設定
	・IKE Version: 作成した DRGを設定
	・Routing Type: BGPを選択
	・BGP ASN: BGPの ASNを設定
	・IPV4 Inside Tunnel Interface - CPE: CPE側 BGP　Peer IPを設定
	・IPV4 Inside Tunnel Interface - Oracle: OCI側 BGP　Peer IPを設定

![05_IPSec作成04.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/7e41f1a1-1465-e6d4-d088-a38e33b72bac.jpeg)


・ Tunnel2 BGP 情報
Tunnel1 BGPと同様に設定

![05_IPSec作成05.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/6b86d6cd-52f2-6c74-b761-f4a4aad51910.jpeg)


4) IPSec Connection作成完了
![05_IPSec作成06.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/3b7450f0-2929-568f-e881-e6800ea6f900.jpeg)

5)  IPSec Connection情報確認
IPSec Connection　作成すると ２つのTunnel用に２つのPublic IPが付与され、このIPを使用して,Cisco Routerを設定します
Cisco RouterとDRG間のIPSec接続が確立されるまで、画面上の　Statusは "Down"になります

![05_IPSec作成07.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/d1056406-52ea-9212-70ad-14f51a6e1d92.jpeg)


# ■ DRG Route Distribution Statements設定
DRGに接続された Attachments(VCN,VPN,FastConnect,RPC等) の Route 制御を行います。
デフォルトでは、DRG へ Import/Export される Route はすべて通す設定(Match All)がされていますので、今回はそのデフォルト値を使用します。
通したくないAttachmentsがある場合は、個別に設定します。

## ● DRG: Import Route Distributions画面
VCN attachments用とそれ以外用(RPC, VC, IPSec attachments)にデフォルトで以下２つの設定がされていることを確認
![DRG_RT01_1.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/bd3036d1-d431-5bc7-aa89-e1c36323a4af.jpeg)


1) Autogenerated Import Route Distribution for ALL routes確認
デフォルトでは、Match Type が Match ALLで設定
![DRG_RT02.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/9394b9bb-1f06-e3e0-0c98-48bc92668659.jpeg)

2) Autogenerated Import Route Distribution for VCN Routes
デフォルトでは、Match Type が Match ALLで設定
![DRG_RT03.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/2ff061b6-d625-2c10-2ddc-fea2df755aef.jpeg)



## ● DRG: Export Route Distributions
デフォルトで以下1つの Export Route Distributions 設定がされていることを確認
![DRG_RT04_2.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/a55fc949-50c1-6a6e-be34-2a97c2e11ce7.jpeg)

1) Default Export Route Distribution for DRG 確認
デフォルトで Match Type が Match ALLで設定
![DRG_RT04.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/5de1de1f-c89e-27b2-71fe-7cd0017539d7.jpeg)

# ■ OCI Route Table設定
今回 VCNだけでなく、Region内にある Object Storgeなど Oracle Services Network (OSN)に配置されたサービスも IPSecを通してオンプレミスから接続できるように、以前の記事を参考にルート表を設定します
・参考: [Transit Routing + IPSec VPN / FastConnectで Object Storage, Autonomous Databaseへ接続してみてみた](https://qiita.com/shirok/items/ec0e5a09346422346fd4)


# ■ Cisco Router設定
[OCI Documentation](https://docs.oracle.com/en-us/iaas/Content/home.htm) の[CPE Configuration](https://docs.oracle.com/en-us/iaas/Content/Network/Reference/ciscoiosCPE.htm)を参考に作成

## ● Cisco初期設定
前回設定した記事を参考にCisco 841Mを設定してインターネット接続できることを確認
・参考: [Cisco 841M: 初期設定してインターネット接続](https://qiita.com/shirok/items/ec430ab16111193ac587)


## ● Cisco Router ログイン

```shell
	Username: cisco
	Password: ******
	Router> 
```

## ● グローバル コンフィギュレーション モード開始

```shell
	Router>enable
	Router#configure terminal
		Enter configuration commands, one per line.  End with CNTL/Z.
```

## ● IPSec 設定
Oracle側では、2つのヘッドエンドが別々のルーターに配置されて冗長性が確保されます。最大の冗長性のためにOracle側でアサインされた２つのTunnelを構成します。
Cisco Systems により検証されたコンフィグ　[IKEv2構成テンプレート](https://docs.oracle.com/ja-jp/iaas/Content/Network/Reference/ciscoiosCPE.htm)を参考として、Ciscoルーターを構成します


```shell
! Keyring (Pre-Shared Key)
crypto ikev2 keyring oracle-vpn-140.204.100.101
 peer oracle_vpn
  address 140.204.100.101
  pre-shared-key local Password01
  pre-shared-key remote Password01

crypto ikev2 keyring oracle-vpn-140.204.100.102
 peer oracle_vpn
  address 140.204.100.102
  pre-shared-key local Password02
  pre-shared-key remote Password02


! IKEv2 and IPSec Policy Configuration
crypto ikev2 proposal oracle_v2_proposal
 encryption aes-cbc-256
 integrity sha384
 group 5

crypto ikev2 policy oracle_v2_policy
 proposal oracle_v2_proposal


! Create an IPSec transform set named 'oracle-vpn-transform' which defines a combination of IPSec (Phase 2) policy options. Specifically, AES256 for encryption and SHA1 for authentication. This is also where tunnel mode is set for IPSec.
! If different parameters are required, modify this template before applying the configuration.

crypto ipsec transform-set oracle-vpn-transform esp-aes 256 esp-sha-hmac
 mode tunnel

! An IPSec profile named 'oracle_v2_ipsec_profile_tunnel#' is created for each tunnel.
crypto ipsec profile oracle_v2_ipsec_profile_tunnel1
 set transform-set oracle-vpn-transform
 set pfs group5
 set security-association lifetime seconds 3600
 set ikev2-profile oracle-vpn-140.204.100.101
!
crypto ipsec profile oracle_v2_ipsec_profile_tunnel2
 set transform-set oracle-vpn-transform
 set pfs group5
 set security-association lifetime seconds 3600
 set ikev2-profile oracle-vpn-140.204.100.102


! IPSec Peers
! Two IKEv2 profiles are created for each Oracle VPN Headend.

crypto ikev2 profile oracle-vpn-140.204.100.101
 match identity remote address 140.204.100.101 255.255.255.255
 identity local address 100.100.100.101
 authentication local pre-share
 authentication remote pre-share
 keyring local oracle-vpn-140.204.100.101
!
crypto ikev2 profile oracle-vpn-140.204.100.102
 match identity remote address 140.204.100.102 255.255.255.255
 identity local address 100.100.100.101
 authentication local pre-share
 authentication remote pre-share
 keyring local oracle-vpn-140.204.100.102


! Virtual Tunnel Interfaces

interface Tunnel1
 ip address 192.168.254.101 255.255.255.252
 ip virtual-reassembly in
 ip tcp adjust-mss 1350
 tunnel source 100.100.100.101
 tunnel mode ipsec ipv4
 tunnel destination 140.204.100.101
 tunnel protection ipsec profile oracle_v2_ipsec_profile_tunnel1
!
interface Tunnel2
 ip address 192.168.254.105 255.255.255.252
 ip virtual-reassembly in
 tunnel source 100.100.100.101
 tunnel mode ipsec ipv4
 tunnel destination 140.204.100.102
 tunnel protection ipsec profile oracle_v2_ipsec_profile_tunnel2
```

## ● BGP設定
Routing Protocolは、BGP動的ルーティングと静的ルーティングを使用できます。
今回は、BGPを使います。
BGP最適パス選択アルゴリズムの操作方法に関するOracle推奨など、VPN接続によるルーティングの詳細は、[Oracle IPSec VPNのルーティング](https://docs.oracle.com/ja-jp/iaas/Content/Network/Tasks/overviewIPsec.htm#ipsec_routing)を参照してください。

```shell
! IP Routing
router bgp 65000
 bgp log-neighbor-changes
 neighbor 192.168.254.102 remote-as 31898
 neighbor 192.168.254.106 remote-as 31898
 !
 address-family ipv4
  network 192.168.0.0 mask 255.255.255.0
  neighbor 192.168.254.102 activate
  neighbor 192.168.254.102 soft-reconfiguration inbound
  neighbor 192.168.254.106 activate
  neighbor 192.168.254.106 soft-reconfiguration inbound
 exit-address-family
```

## ● Internet Facing Access List設定

```shell
! Update Any Internet Facing Access List to Allow IPSec and ISAKMP Packets

! You may need to allow IPSec and ISAKMP packets out your internet facing interface.
! Uncomment below lines to create a new ACL allowing IPSec and ISAKMP traffic and apply it to the outside interface.

ip access-list extended INTERNET-INGRESS
 permit udp host 140.204.100.101 host 100.100.100.101 eq isakmp
 permit esp host 140.204.100.101 host 100.100.100.101
 permit udp host 140.204.100.102 host 100.100.100.101 eq isakmp
 permit esp host 140.204.100.102 host 100.100.100.101
 permit icmp any any echo
 permit icmp any any echo-reply
 permit icmp any any unreachable

 interface ${outsideInterface}
  ip access-group INTERNET-INGRESS in
```

# ■ VPN接続確認
## ● OCI IPSec Connection画面確認
作成したIPSec Connectionの "IPSec Status"と "IPV4 BGP Status"が UPしていることを確認
![10_IPSec接続UP.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/ee786201-5b0d-e74f-9544-51b32fae7a2f.jpeg)


## ● CISCO Router確認
### ・ IPSec SA確立確認

```
Router# show crypto session
Crypto session current status

Interface: Tunnel1
Profile: oracle-vpn-140.204.100.101
Session status: UP-ACTIVE
Peer: 140.204.100.101 port 500
  Session ID: 1125
  IKEv2 SA: local 100.100.100.101/500 remote 140.204.100.101/500 Active
  IPSEC FLOW: permit ip 0.0.0.0/0.0.0.0 0.0.0.0/0.0.0.0
        Active SAs: 2, origin: crypto map

Interface: Tunnel2
Profile: oracle-vpn-140.204.100.102
Session status: UP-ACTIVE
Peer: 140.204.100.102 port 500
  Session ID: 1138
  IKEv2 SA: local 100.100.100.101/500 remote 140.204.100.102/500 Active
  IPSEC FLOW: permit ip 0.0.0.0/0.0.0.0 0.0.0.0/0.0.0.0
        Active SAs: 2, origin: crypto map
```



### ・ IPSec 暗号化マップ確認
```
Router# show crypto map
        Interfaces using crypto map NiStTeSt1:

Crypto Map: "Tunnel1-head-0" IKEv2 profile: oracle-vpn-140.204.100.101

Crypto Map IPv4 "Tunnel1-head-0" 65536 ipsec-isakmp
        IKEv2 Profile: oracle-vpn-140.204.100.101
        Profile name: oracle_ipsec_profile_Tunnel1
        Security association lifetime: 4608000 kilobytes/3600 seconds
        Responder-Only (Y/N): N
        PFS (Y/N): Y
        DH group:  group5
        Mixed-mode : Disabled
        Transform sets={
                oracle-vpn-transform:  { esp-256-aes esp-sha-hmac  } ,
        }

Crypto Map IPv4 "Tunnel1-head-0" 65537 ipsec-isakmp
        Map is a PROFILE INSTANCE.
        Peer = 140.204.100.101
        IKEv2 Profile: oracle-vpn-140.204.100.101
        Extended IP access list
            access-list  permit ip any any
        Current peer: 140.204.100.101
        Security association lifetime: 4608000 kilobytes/3600 seconds
        Responder-Only (Y/N): N
        PFS (Y/N): Y
        DH group:  group5
        Mixed-mode : Disabled
        Transform sets={
                oracle-vpn-transform:  { esp-256-aes esp-sha-hmac  } ,
        }
        Always create SAs
        Interfaces using crypto map Tunnel1-head-0:
                Tunnel1


Crypto Map: "Tunnel2-head-0" IKEv2 profile: oracle-vpn-140.204.100.102

Crypto Map IPv4 "Tunnel2-head-0" 65536 ipsec-isakmp
        IKEv2 Profile: oracle-vpn-140.204.100.102
        Profile name: oracle_ipsec_profile_Tunnel2
        Security association lifetime: 4608000 kilobytes/3600 seconds
        Responder-Only (Y/N): N
        PFS (Y/N): Y
        DH group:  group5
        Mixed-mode : Disabled
        Transform sets={
                oracle-vpn-transform:  { esp-256-aes esp-sha-hmac  } ,
        }

Crypto Map IPv4 "Tunnel2-head-0" 65537 ipsec-isakmp
        Map is a PROFILE INSTANCE.
        Peer = 140.204.100.102
        IKEv2 Profile: oracle-vpn-140.204.100.102
        Extended IP access list
            access-list  permit ip any any
        Current peer: 140.204.100.102
        Security association lifetime: 4608000 kilobytes/3600 seconds
        Responder-Only (Y/N): N
        PFS (Y/N): Y
        DH group:  group5
        Mixed-mode : Disabled
        Transform sets={
                oracle-vpn-transform:  { esp-256-aes esp-sha-hmac  } ,
        }
        Always create SAs
        Interfaces using crypto map Tunnel2-head-0:
                Tunnel2
```

### ・ BGP UP確認

```shell
Router#show ip bgp summary
      BGP router identifier 192.168.254.105, local AS number 65000
      BGP table version is 20, main routing table version 20
      10 network entries using 1440 bytes of memory
      19 path entries using 1520 bytes of memory
      2/2 BGP path/bestpath attribute entries using 320 bytes of memory
      1 BGP AS-PATH entries using 24 bytes of memory
      0 BGP route-map cache entries using 0 bytes of memory
      0 BGP filter-list cache entries using 0 bytes of memory
      BGP using 3304 total bytes of memory
      BGP activity 10/0 prefixes, 37/18 paths, scan interval 60 secs

      Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
      192.168.254.102 4        31898      16      19       20    0    0 00:11:31        9
      192.168.254.106 4        31898      19      23       20    0    0 00:15:09        9
```

### ・ BGP Neighbors Received-routes確認
OCIから受信した Routeを確認します。
今回、Tokyo Regionの OSN と VCNのSubnetのRoute情報が、OCIからCiscoルーターへ送信されていることを確認
Object Storage,ADB等のVCN外のサービスがあるOracle Services Network(OSN)のIP Address Rangesは、[VCNおよびOracle Services Network用のパブリックIPアドレス]の JSONファイルにある"OSN"と"OBJECT_STORAGE"項目部分のCIDRです。


```shell
Router#show ip bgp neighbors 192.168.254.102 received-routes
      BGP table version is 20, local router ID is 192.168.254.105
      Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
                  r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
                  x best-external, a additional-path, c RIB-compressed,
      Origin codes: i - IGP, e - EGP, ? - incomplete
      RPKI validation codes: V valid, I invalid, N Not found

      Network          Next Hop            Metric LocPrf Weight Path
      *>  10.0.0.0/24      192.168.254.102                        0 31898 i
      *>  134.70.80.0/23   192.168.254.102                        0 31898 i
      *>  134.70.82.0/23   192.168.254.102                        0 31898 i
      *>  140.91.32.0/23   192.168.254.102                        0 31898 i
      *>  140.204.8.128/25 192.168.254.102                        0 31898 i
      *>  192.29.36.0/22   192.168.254.102                        0 31898 i
      *>  192.29.40.0/22   192.168.254.102                        0 31898 i
      *>  192.29.44.0/25   192.168.254.102                        0 31898 i

      Total number of prefixes 9
```

### ・ BGP Neighbors Advertised-routes確認
OCI にアドバタイズされたルートを確認

```shell
Router#show ip bgp neighbors 192.168.254.102 advertised-routes
    BGP table version is 14, local router ID is 192.168.254.105
    Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
                r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
                x best-external, a additional-path, c RIB-compressed,
    Origin codes: i - IGP, e - EGP, ? - incomplete
    RPKI validation codes: V valid, I invalid, N Not found

        Network          Next Hop            Metric LocPrf Weight Path
        *>  10.0.0.0/24      192.168.254.102                        0 31898 i
        *>  134.70.80.0/23   192.168.254.102                        0 31898 i
        *>  134.70.82.0/23   192.168.254.102                        0 31898 i
        *>  140.91.32.0/23   192.168.254.102                        0 31898 i
        *>  140.204.8.128/25 192.168.254.102                        0 31898 i
        *>  192.29.36.0/22   192.168.254.102                        0 31898 i
        *>  192.29.40.0/22   192.168.254.102                        0 31898 i
        *>  192.29.44.0/25   192.168.254.102                        0 31898 i
        *>  192.168.0.0/24   0.0.0.0                                0 32768 i
```

### ・Router の Route情報確認
### 

```shell
Router#show ip route
	Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
		D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
		N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
		E1 - OSPF external type 1, E2 - OSPF external type 2
		i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
		ia - IS-IS inter area, * - candidate default, U - per-user static route
		o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
		a - application route
		+ - replicated route, % - next hop override, p - overrides from PfR

	Gateway of last resort is 0.0.0.0 to network 0.0.0.0

	S*    0.0.0.0/0 is directly connected, Dialer1
		10.0.0.0/24 is subnetted, 2 subnets
	B        10.0.0.0 [20/0] via 192.168.254.102, 00:02:59
		100.0.0.0/32 is subnetted, 1 subnets
	C        100.100.100.101 is directly connected, Dialer1
		134.70.0.0/23 is subnetted, 2 subnets
	B        134.70.80.0 [20/0] via 192.168.254.102, 00:02:59
	B        134.70.82.0 [20/0] via 192.168.254.102, 00:02:59
		140.91.0.0/23 is subnetted, 1 subnets
	B        140.91.32.0 [20/0] via 192.168.254.102, 00:02:59
		140.204.0.0/25 is subnetted, 1 subnets
	B        140.204.8.128 [20/0] via 192.168.254.102, 00:02:59
		163.139.0.0/32 is subnetted, 1 subnets
	C        163.139.100.35 is directly connected, Dialer1
	B     192.29.36.0/22 [20/0] via 192.168.254.102, 00:02:59
	B     192.29.40.0/22 [20/0] via 192.168.254.102, 00:02:59
		192.29.44.0/25 is subnetted, 1 subnets
	B        192.29.44.0 [20/0] via 192.168.254.102, 00:02:59
		192.168.0.0/24 is variably subnetted, 2 subnets, 2 masks
	C        192.168.0.0/24 is directly connected, Vlan1
	L        192.168.0.1/32 is directly connected, Vlan1
		192.168.254.0/24 is variably subnetted, 4 subnets, 2 masks
	C        192.168.254.100/30 is directly connected, Tunnel1
	L        192.168.254.101/32 is directly connected, Tunnel1
	C        192.168.254.104/30 is directly connected, Tunnel2
	L        192.168.254.105/32 is directly connected, Tunnel2
```







# ■ Tunnel1優先経路(対象ルーティング)設定
非対称ルーティングを避けるため、双方向(OCI->CPE, CPE->OCI)が Tunnel1 を優先経路とするよう、CiscoルーターのBGP設定 AS_PATHプリペンドと WEIGHTアトリビュート (もしくはLocal-Preference等)を必要に応じて設定
今回は、対象ルーティングになるよう設定してみてみます

## ● DRG Route 確認
1) DRG画面
Resources ＞ DRG Route Tables をクリックし、DRG Route Tables にある IPSec attachmentsのRoute Tableをクリック
![01_設定前DRGルート表01.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/ff8dbc1c-a6b1-7d16-b93e-c2cfdfc3d985.jpeg)


2) Drg Route Table for IPSec attachments 画面
[Get All ROute Roules]をクリック
![01_設定前DRGルート表02.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/e9e139eb-9e18-ada0-8086-3e14353cd46a.jpeg)

3) Get All Route Rules 画面
DRG Route Rules 情報では、Tunnel2 が Active であり　Tunnel01 が Conflict Stutas でActive
で使用されておらず、Standby経路となっていて、Cisco の show ip route 情報では、192.168.254.102 の Tunnel1 が使用されているため、非対称ルーティングであることが確認できます。
![01_設定前DRGルート表03.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/fcd2792c-117d-c3d1-dd74-bcfd8fdaa2e7.jpeg)




## ● AS_PATH Prepend 設定 (OCI -> Cisco経路)
AS_PATHアトリビュートは、Route-Mapの設定で、自身の AS番号に AS番号を追加することによって EBGPピアに ASパスを長く見せることができます。
この機能はAS_PATHプリペンドと言い、このコマンドで指定したAS番号は、AS_PATHの先頭に追加されASパスを長くすることができます。

・AS_PATHプリペンドの設定

	　(config)# route-map map-tag permit | deny [ seq-number ]
	　(config-route-map)# match condition
	　(config-route-map)# set as-path prepend as-number [ as-number ]


・設定実行
PRE-AS に合致するルートの AS_PATHに、AS番号65000 を 2つ追加

```Shell
ip prefix-list PRE-AS permit 192.168.0.0/24

route-map R-ASPRE permit 10
 match ip address prefix-list PRE-AS
 set as-path prepend 65000 65000
route-map R-ASPRE permit 20

router bgp 65000
  neighbor 192.168.254.106 route-map R-ASPRE out
```

## ● Weight Attribute(Cisco -> OCI経路)
WEIGHTアトリビュートは、CIsco 独自の BGPアトリビュートであり、ベストパス選択のアルゴリズム比較の最初に使用されるアトリビュートで WEIGHT値が最大のルートが優先されます。
1台の BGPルータのASから出力されるパス(Route)が複数ある場合などで WEIGHTアトリビュートを使用します
他メーカーのルーターでは、Local-Preference等を使用します

2) WEIGHTアトリビュート - 設定
Tunnel1(192.168.254.102)側のWEIGHTを200、Tunnel2(192.168.254.106)側のWEIGHTを100設定し、Tunnel1を優先経路へ設定

```Shell
router bgp 65000
  neighbor 192.168.254.102 weight 200
  neighbor 192.168.254.106 weight 100
```



## ● Route情報確認
### 1) Ciscoルーター Route確認

**・show ip bgp**
OCI の ASN#31898 に対してWeight列に設定した WEIGHTアトリビュート値 200と 100が設定されていることを確認


```Shell
Router#show ip bgp
	BGP table version is 32, local router ID is 192.168.254.105
	Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
				r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
				x best-external, a additional-path, c RIB-compressed,
	Origin codes: i - IGP, e - EGP, ? - incomplete
	RPKI validation codes: V valid, I invalid, N Not found

		Network          Next Hop            Metric LocPrf Weight Path
	*>  10.1.0.0/24      192.168.254.102                      200 31898 i
	*                    192.168.254.106                      100 31898 i
	*>  134.70.80.0/23   192.168.254.102                      200 31898 i
	*                    192.168.254.106                      100 31898 i
	*>  134.70.82.0/23   192.168.254.102                      200 31898 i
	*                    192.168.254.106                      100 31898 i
	*>  140.91.32.0/23   192.168.254.102                      200 31898 i
	*                    192.168.254.106                      100 31898 i
	*>  140.204.8.128/25 192.168.254.102                      200 31898 i
	*                    192.168.254.106                      100 31898 i
	*>  192.29.36.0/22   192.168.254.102                      200 31898 i
	*                    192.168.254.106                      100 31898 i
	*>  192.29.40.0/22   192.168.254.102                      200 31898 i
	*                    192.168.254.106                      100 31898 i
	*>  192.29.44.0/25   192.168.254.102                      200 31898 i
	*                    192.168.254.106                      100 31898 i
	*>  192.168.0.0/24 0.0.0.0                  0         32768 i
```


**・show ip route**
OCIへの Route は、192.168.254.102 の Tunnel1 が使用されていることを確認


```Shell
Router#show ip route
	Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
		D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
		N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
		E1 - OSPF external type 1, E2 - OSPF external type 2
		i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
		ia - IS-IS inter area, * - candidate default, U - per-user static route
		o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
		a - application route
		+ - replicated route, % - next hop override, p - overrides from PfR

	Gateway of last resort is 0.0.0.0 to network 0.0.0.0

	S*    0.0.0.0/0 is directly connected, Dialer1
		10.0.0.0/24 is subnetted, 2 subnets
	B        10.1.0.0 [20/0] via 192.168.254.102, 00:12:22
		100.0.0.0/32 is subnetted, 1 subnets
	C        100.100.100.101 is directly connected, Dialer1
		134.70.0.0/23 is subnetted, 2 subnets
	B        134.70.80.0 [20/0] via 192.168.254.102, 00:12:22
	B        134.70.82.0 [20/0] via 192.168.254.102, 00:12:22
		140.91.0.0/23 is subnetted, 1 subnets
	B        140.91.32.0 [20/0] via 192.168.254.102, 00:01:19
		140.204.0.0/25 is subnetted, 1 subnets
	B        140.204.8.128 [20/0] via 192.168.254.102, 00:01:19
		163.139.0.0/32 is subnetted, 1 subnets
	C        163.139.100.35 is directly connected, Dialer1
	B     192.29.36.0/22 [20/0] via 192.168.254.102, 00:01:19
	B     192.29.40.0/22 [20/0] via 192.168.254.102, 00:01:19
		192.29.44.0/25 is subnetted, 1 subnets
	B        192.29.44.0 [20/0] via 192.168.254.102, 00:01:19
		192.168.0.0/24 is variably subnetted, 2 subnets, 2 masks
	C        192.168.0.0/24 is directly connected, Vlan1
	L        192.168.0.1/32 is directly connected, Vlan1
		192.168.254.0/24 is variably subnetted, 4 subnets, 2 masks
	C        192.168.254.100/30 is directly connected, Tunnel1
	L        192.168.254.101/32 is directly connected, Tunnel1
	C        192.168.254.104/30 is directly connected, Tunnel2
	L        192.168.254.105/32 is directly connected, Tunnel2
```



### 2) DRG Route確認
優先設定が有効化され、Tunnel01 が Activeに変わり、対象ルーティングになったことを確認
![02_設定後DRGルート表.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/109087/d946481f-986c-1d7b-a573-b153ebc9411f.jpeg)












# ■ 接続確認
## ● On-Premises -> OCI Compute Instance接続確認
### ・Trace Route確認

```shell
onp-inst01:~ user$ traceroute -I 10.0.0.2
	traceroute to 10.0.0.2 (10.0.0.2), 64 hops max, 72 byte packets
	1  * * *
	2  * * *
	3  10.0.0.2 (10.0.0.2)  6.555 ms  6.708 ms  7.079 ms
```

### ・Ping疎通確認

```shell
onp-inst01:~ user$ ping 10.0.0.2 -c 3
	PING 10.0.0.2 (10.0.0.2): 56 data bytes
	64 bytes from 10.0.0.2: icmp_seq=0 ttl=62 time=6.940 ms
	64 bytes from 10.0.0.2: icmp_seq=1 ttl=62 time=6.780 ms
	64 bytes from 10.0.0.2: icmp_seq=2 ttl=62 time=5.916 ms

	--- 10.0.0.2 ping statistics ---
	3 packets transmitted, 3 packets received, 0.0% packet loss
	round-trip min/avg/max/stddev = 5.916/6.545/6.940/0.450 ms
```

### ・ssh接続確認

```shell
onp-inst01:~ user$ ssh -i id_rsa opc@10.0.0.2 hostname
	tokyo-inst
```

## ● On-Premises -> OCI Object Storage接続確認

### ・Trace Route確認

```shell
onp-inst01:~ user$ traceroute -I objectstorage.ap-Tokyo-1.oraclecloud.com
	traceroute to objectstorage.ap-tokyo-1.oci.oraclecloud.com (134.70.80.3), 64 hops max, 72 byte packets
	1  * * *
	2  * * *
	3  objectstorage.ap-tokyo-1.oci.oraclecloud.com (134.70.80.3)  11.819 ms  10.322 ms  12.619 ms
```

### ・Ping疎通確認

```shell
onp-inst01:~ user$ ping objectstorage.ap-Tokyo-1.oraclecloud.com -c 3
	PING objectstorage.ap-tokyo-1.oci.oraclecloud.com (134.70.80.3): 56 data bytes
	64 bytes from 134.70.80.3: icmp_seq=0 ttl=62 time=10.229 ms
	64 bytes from 134.70.80.3: icmp_seq=1 ttl=62 time=6.742 ms
	64 bytes from 134.70.80.3: icmp_seq=2 ttl=62 time=6.178 ms

	--- objectstorage.ap-tokyo-1.oci.oraclecloud.com ping statistics ---
	3 packets transmitted, 3 packets received, 0.0% packet loss
	round-trip min/avg/max/stddev = 6.178/7.716/10.229/1.792 ms
```


# ■ 設定保存
設定を保存するには、次のコマンドを使用して startup-config に実行 unning-config を保存
```
	Router#copy running-config startup-config
		Destination filename [startup-config]?
		Building configuration...
		[OK]
```

# ■ 参考
**● OCI Documents**
　・[CPE Configuration](https://docs.oracle.com/en-us/iaas/Content/Network/Tasks/configuringCPE.htm)
　・[CPE Configuration: Cisco IOS](https://docs.oracle.com/en-us/iaas/Content/Network/Reference/ciscoiosCPE.htm)
　・[Connectivity Redundancy Guide](https://docs.oracle.com/en-us/iaas/Content/Resources/Assets/whitepapers/connectivity-redundancy-guide.pdf)

**● CIsco Documents**
　・[Cisco 841M J シリーズ](https://www.cisco.com/c/ja_jp/solutions/small-business/on-premise/product-network/product-841mj.html)
　・[Cisco 841M ドキュメント](https://www.cisco.com/c/ja_jp/solutions/small-business/on-premise/product-network/product-841mj.html#~stickynav=4)
　・[Cisco 800M データシート](https://www.cisco.com/c/ja_jp/products/collateral/routers/800m-integrated-services-router-isr/datasheet-c78-732678.html)
　・[Cisco Start ユーザ サイトファームウェア ダウンロード](https://www.cisco.com/c/m/ja_jp/customer/cisco-start-user-site/download.html)
　・[BGPルートがアドバタイズされない場合のトラブルシューティング](https://www.cisco.com/c/ja_jp/support/docs/ip/border-gateway-protocol-bgp/19345-bgp-noad.html)

**● infraexpert.com**
・[BGP AS_PATH - Cisco Config](https://www.infraexpert.com/study/bgpz13.html)
・[route-map - redistribute](https://www.infraexpert.com/study/routecontrol11.html)
・[BGP WEIGHT - Cisco Config](https://www.infraexpert.com/study/bgpz25.html#:~:text=WEIGHT%E3%82%A2%E3%83%88%E3%83%AA%E3%83%93%E3%83%A5%E3%83%BC%E3%83%88%E3%81%AF%E3%80%81%E3%82%B7%E3%82%B9%E3%82%B3%E7%8B%AC%E8%87%AA,%E4%BD%BF%E7%94%A8%E3%81%95%E3%82%8C%E3%82%8B%E3%82%A2%E3%83%88%E3%83%AA%E3%83%93%E3%83%A5%E3%83%BC%E3%83%88%E3%81%A7%E3%81%99%E3%80%82&text=WEIGHT%E5%80%A4%E3%81%AE%E3%83%87%E3%83%95%E3%82%A9%E3%83%AB%E3%83%88%E3%81%AF,%E3%83%AB%E3%83%BC%E3%83%88%E3%81%AF%E3%80%8C%200%20%E3%80%8D%E3%81%A7%E3%81%99%E3%80%82)

**● Blog**
・[Cisco 841M: 初期設定してインターネット接続してみてみた](https://qiita.com/shirok/items/ec430ab16111193ac587)