CiscoルータでのVTI+IKEv2設定(NAT越し)~対VyOS編~

ということで,Cisco~VyOS間でも試した。

検証した結果わかったことは以下の通り。

・VyOS1.1.x台ではVTI+IKEv2ではVPNは張れない。
   いや, 張れるんだけど(Phase2まで上がるんだけど) 疎通が取れない。
・EC2のElastic IPで,末尾が0だと(サブネットゼロだと)Cisco側でネットワークアドレスとしてみなされるらくしPhase2で失敗する。(たとえ ip subnet-zero が入っていたとしても)
<追記>
・改めてCisco~VyOS間のトラフィックを確認したら, 正常にトラフィックが流れていないことに気がついた。VyOSからソースIFをVTI指定してのPingでないとトラフィックがトンネルを通らない。Beta版のバグなのかな。
なので, 現時点ではVPNは張れるがまともに使えないという状況。要調査。

VyOSのBeta版はこちらからダウンロードする。
https://downloads.vyos.io/?dir=rolling/current/amd64
今回のバージョンはvyos-999.201802070337-amd64.iso
参考までにアップグレード方法を。
本家にやり方ありますが一応。

$ conf
# set system name-server 8.8.8.8 (Google先生スミマセン)
# commit
# exit
$ sudo su
# wget beta版URL
# exit
$ add system image file
$ show system image
The system currently has the following image(s) installed:

1: 999.201802070337- (default boot)
2: 1.1.8 (running image)
$ reboot

これでオッケー。
なお,設定はVTIのときとほぼ同じで至ってシンプル。

set interfaces vti vti1 address '10.10.10.1/30'
~途中省略~
set vpn ipsec esp-group ESP compression 'disable'
set vpn ipsec esp-group ESP lifetime '3600'
set vpn ipsec esp-group ESP mode 'tunnel'
set vpn ipsec esp-group ESP pfs 'dh-group14'
set vpn ipsec esp-group ESP proposal 1 encryption 'aes256'
set vpn ipsec esp-group ESP proposal 1 hash 'sha256'
set vpn ipsec ike-group IKE ikev2-reauth 'no'
set vpn ipsec ike-group IKE key-exchange 'ikev2'
set vpn ipsec ike-group IKE lifetime '3600'
set vpn ipsec ike-group IKE proposal 1 dh-group '14'
set vpn ipsec ike-group IKE proposal 1 encryption 'aes256'
set vpn ipsec ike-group IKE proposal 1 hash 'sha256'
set vpn ipsec ipsec-interfaces interface 'eth0'
set vpn ipsec site-to-site peer B.B.B.B authentication id '10.200.10.20'
set vpn ipsec site-to-site peer B.B.B.B authentication mode 'pre-shared-secret'
set vpn ipsec site-to-site peer B.B.B.B authentication pre-shared-secret 'password'
set vpn ipsec site-to-site peer B.B.B.B authentication remote-id '192.168.1.2'
set vpn ipsec site-to-site peer B.B.B.B connection-type 'initiate'
set vpn ipsec site-to-site peer B.B.B.B default-esp-group 'ESP'
set vpn ipsec site-to-site peer B.B.B.B ike-group 'IKE'
set vpn ipsec site-to-site peer B.B.B.B ikev2-reauth 'inherit'
set vpn ipsec site-to-site peer B.B.B.B local-address '10.200.10.20'
set vpn ipsec site-to-site peer B.B.B.B vti bind 'vti1'
set vpn ipsec site-to-site peer B.B.B.B vti esp-group 'ESP'

これでトンネル間の疎通が取れた。

vyos@VPN1:~$ ping 10.10.10.2 interface vti1 PING 10.10.10.2 (10.10.10.2) from 10.10.10.1 vti1: 56(84) bytes of data. 64 bytes from 10.10.10.2: icmp_seq=1 ttl=255 time=6.92 ms 64 bytes from 10.10.10.2: icmp_seq=2 ttl=255 time=6.86 ms

ちなみにVyOS1.1.8(以前)の場合,show crypto session や show vpn ipsec sa でステータスがアップになるが,疎通が取れない。VyOS側で確認するとトンネルインタフェースがAdmin Down状態となってしまう。(原因不明)

vyos@VPN2:~$ sh int vti vti1
vti1@NONE: mtu 1500 qdisc noqueue state DOWN group default
link/ipip 10.200.10.20 peer B.B.B.B
inet 10.10.20.1/30 scope global vti1
valid_lft forever preferred_lft forever

RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collisions
0 0 0 0 0 0

VyOS1.1.x系はIKEv2に対してはlimited supportということで,今回は現時点で最新のベータバージョンを利用した。

CiscoルータでのVTI+IKEv2設定(NAT越し)

EC2にCisco1000vを立て, 自宅とVPNを張る。
以前, VyOSとでGRE over IPSecVTIと2パターンやったが, 今回はVTI+IKEv2でやる。
まずはCisco同士でトライ。

はじめに

「何故IKEv2でやろうとしたか」
単純にv2だからより安全なんだろうと思ったから。
IKEv1と何が違うのかは様々なサイトに詳しく書いてある。
・UNIVERGE IXシリーズ FAQ「IKEv2に関するFAQ
・Cisco IOS セキュリティ コンフィギュレーション ガ イド「Cisco IOS セキュリティ コンフィギュレーション ガ イドインターネット キー エクスチェンジ バージョ ン 2(IKEv2)の設定
個人的には設定の可視化レベルがcrypto mapよりは高いと感じた。P1のポリシーもピア毎に指定できるのでこのあたりは便利だと思う。(Site-to-Siteだとあまり恩恵は感じられないかもしれない)

構成概要

2台のルータでIPSecをVTI+IKEv2で張る。
それぞれのルータはNAT越しに通信する。
鍵交換はPSK。
暗号化周りはAES256, SHA2-256, DH 14。

構成概略図

前提条件

・EC2上にインスタンス作成済
・そのインスタンスにElastic IP割当済
・適切にセキュリティグループは設定済(UDP500・4500は許可等)
・自宅のGlobal IPは固定前提
・ブロードバンドルータでポートフォワーディング設定済

設定手順

Config上から流し込んでいくイメージでOK。
・IKEv2のプロポーザル設定
・IKEv2のポリシー設定
・IKEv2のKey設定
・IKEv2のプロファイル設定
・トランスフォームセット設定
・IPSECプロファイル設定
・トンネルインタフェース作成
・VTI適用

いざ設定

Configを抜粋。
基本的にこのまま流し込めばOK。

C841M
C1000v
!プロポーザル設定
crypto ikev2 proposal IKEv2_Proposal
encryption aes-cbc-256
integrity sha256
group 14

! ポリシー設定
crypto ikev2 policy IKEv2_Policy
proposal IKEv2_Proposal

!キー設定
crypto ikev2 keyring IKEv2_Key_Cisco
peer C1000V
address A.A.A.A
pre-shared-key password

! プロファイル設定
crypto ikev2 profile IKEv2_Profile_Cisco
match identity remote address 10.200.10.12 255.255.255.255
identity local address 192.168.1.2
authentication remote pre-share
authentication local pre-share
keyring local IKEv2_Key_Cisco
lifetime 3600

! トランスフォームセット設定
crypto ipsec transform-set IPSEC esp-aes 256 esp-sha256-hmac
mode tunnel

! IPSECプロファイル設定
crypto ipsec profile VTI_Cisco
set transform-set IPSEC
set ikev2-profile IKEv2_Profile_Cisco

! Tunnelインタフェース設定
interface Tunnel1
ip address 172.16.10.1 255.255.255.0
tunnel source G0/0
tunnel mode ipsec ipv4
tunnel destination A.A.A.A
tunnel protection ipsec profile VTI_Cisco
! プロポーザル設定
crypto ikev2 proposal IKEv2_Proposal
encryption aes-cbc-256
integrity sha256
group 14

! ポリシー設定
crypto ikev2 policy IKEv2_Policy
proposal IKEv2_Proposal

!キー設定
crypto ikev2 keyring IKEv2_Key_Cisco
peer C841M
address B.B.B.B
pre-shared-key password

! プロファイル設定
crypto ikev2 profile IKEv2_Profile_Cisco
match identity remote address 192.168.1.2 255.255.255.255
identity local address 10.1.1.10
authentication remote pre-share
authentication local pre-share
keyring local IKEv2_Key_Cisco
lifetime 3600

! トランスフォームセット設定
crypto ipsec transform-set IPSEC esp-aes 256 esp-sha256-hmac
mode tunnel

! IPSECプロファイル設定
crypto ipsec profile VTI_Cisco
set transform-set IPSEC
set ikev2-profile IKEv2_Profile_Cisco

! Tunnelインタフェース設定
interface Tunnel1
ip address 172.16.10.2 255.255.255.0
tunnel source G0/0
tunnel mode ipsec ipv4
tunnel destination B.B.B.B
tunnel protection ipsec profile VTI_Cisco

確認

c1000v#sh crypto ikev2 sa
IPv4 Crypto IKEv2 SA

Tunnel-id Local Remote fvrf/ivrf Status
1 10.1.1.10/4500 B.B.B.B/4500 none/none READY
Encr: AES-CBC, keysize: 256, PRF: SHA256, Hash: SHA256, DH Grp:14, Auth sign: PSK, Auth verify: PSK
Life/Active Time: 3600/2111 sec

IPv6 Crypto IKEv2 SA

c1000v#sh crypto ipsec sa

interface: Tunnel1
Crypto map tag: Tunnel1-head-0, local addr 10.1.1.10

protected vrf: (none)
local ident (addr/mask/prot/port): (0.0.0.0/0.0.0.0/0/0)
remote ident (addr/mask/prot/port): (0.0.0.0/0.0.0.0/0/0)
current_peer B.B.B.B port 4500
PERMIT, flags={origin_is_acl,}
#pkts encaps: 10, #pkts encrypt: 10, #pkts digest: 10
#pkts decaps: 10, #pkts decrypt: 10, #pkts verify: 10
#pkts compressed: 0, #pkts decompressed: 0
#pkts not compressed: 0, #pkts compr. failed: 0
#pkts not decompressed: 0, #pkts decompress failed: 0
#send errors 0, #recv errors 0

local crypto endpt.: 10.1.1.10, remote crypto endpt.: B.B.B.B
plaintext mtu 1422, path mtu 1500, ip mtu 1500, ip mtu idb GigabitEthernet1
current outbound spi: 0x3478CA01(880331265)
PFS (Y/N): N, DH group: none

inbound esp sas:
spi: 0x9AF7C1FF(2599928319)
transform: esp-256-aes esp-sha256-hmac ,
in use settings ={Tunnel UDP-Encaps, }
conn id: 2068, flow_id: CSR:68, sibling_flags FFFFFFFF80000048, crypto map: Tunnel1-head-0
sa timing: remaining key lifetime (k/sec): (4607998/1485)
IV size: 16 bytes
replay detection support: Y
Status: ACTIVE(ACTIVE)

inbound ah sas:

inbound pcp sas:

outbound esp sas:
spi: 0x3478CA01(880331265)
transform: esp-256-aes esp-sha256-hmac ,
in use settings ={Tunnel UDP-Encaps, }
conn id: 2067, flow_id: CSR:67, sibling_flags FFFFFFFF80000048, crypto map: Tunnel1-head-0
sa timing: remaining key lifetime (k/sec): (4607999/1485)
IV size: 16 bytes
replay detection support: Y
Status: ACTIVE(ACTIVE)

outbound ah sas:

outbound pcp sas:

c1000v#sh crypto session
Crypto session current status

Interface: Tunnel1
Profile: IKEv2_Profile
Session status: UP-ACTIVE
Peer: B.B.B.B port 4500
Session ID: 6
IKEv2 SA: local 10.1.1.10/4500 remote B.B.B.B/4500 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

以上, お疲れ様でした。

AWS上のVyosと家のC841とでIPSecを試す~VTI編~

VTIでも設定したのでメモ・・・。

ACLいらないし, GRE分のオーバーヘッド(24バイト)も減るしこっちのほうがなんかいいかも。
# IP以外のプロトコルなんてあんま使わないしな。

 ■ MTU
#sh int tu1
Tunnel1 is up, line protocol is up
  Hardware is Tunnel
  Internet address is 192.168.48.234/29
  MTU 17862 bytes, BW 100 Kbit/sec, DLY 50000 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation TUNNEL, loopback not set
  Keepalive set (5 sec), retries 3
  Tunnel linestate evaluation up
  Tunnel source 192.168.1.2 (Vlan100), destination 52.196.175.0
   Tunnel Subblocks:
      src-track:
         Tunnel1 source tracking subblock associated with Vlan100
          Set of tunnels with source Vlan100, 1 member (includes iterators), on interface <OK>
  Tunnel protocol/transport IPSEC/IP
  Tunnel TTL 255
  Tunnel transport MTU 1422 bytes
  Tunnel transmit bandwidth 8000 (kbps)
  Tunnel receive bandwidth 8000 (kbps)
  Tunnel protection via IPSec (profile “VTI”)
  Last input 19:27:49, output 18:54:11, output hang never
  Last clearing of “show interface” counters 3d17h
  Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 330
  Queueing strategy: fifo
  Output queue: 0/0 (size/max)
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     12728 packets input, 1119256 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     68893 packets output, 4199880 bytes, 0 underruns
     0 output errors, 0 collisions, 0 interface resets
     0 unknown protocol drops
     0 output buffer failures, 0 output buffers swapped out
 permit ip host 172.16.1.1 host 172.16.1.2

以下, Config抜粋。

■ Cisco 抜粋
!
crypto isakmp policy 5
 encr aes 256
 hash sha256
 authentication pre-share
 group 14
 lifetime 3600
crypto isakmp key aws address A.A.A.A  255.255.255.255
crypto isakmp keepalive 30 30
!
!
crypto ipsec transform-set IPSEC esp-aes 256 esp-sha256-hmac 
 mode tunnel
!
crypto ipsec profile VTI
 set transform-set IPSEC
 set pfs group14

!
!
!
interface Tunnel1
 ip address 192.168.254.1 255.255.255.0
 ip mtu 1422   ! ← いらないかも。 不要でした。 ※
 ip ospf network broadcast
 ip ospf hello-interval 5
 keepalive 5 3
 tunnel source Vlan100
 tunnel mode ipsec ipv4
 tunnel destination A.A.A.A
 tunnel protection ipsec profile VTI

!
interface Vlan100
 ip address 192.168.1.2 255.255.255.0
 ip virtual-reassembly in
!
!
!
router ospf 1
 network 192.168.10.0 0.0.0.255 area 0
 network 192.168.254.0 0.0.0.255 area 0
!
!
ip access-list extended AWS_GRE
!
 permit ip host 172.16.1.1 host 172.16.1.2

※ VTIはMTUを自動計算するから設定は不要(Ciscoのページ参照

■ Vyos 抜粋
set interfaces loopback lo address ‘172.16.1.2/32’
set interfaces vti vti1 address ‘192.168.48.233/29’
set interfaces vti vti1 ip ospf dead-interval ’20’
set interfaces vti vti1 ip ospf hello-interval ‘5’
set interfaces vti vti1 ip ospf network ‘broadcast’
set interfaces vti vti1 ip ospf priority ‘1’
set interfaces vti vti1 ip ospf retransmit-interval ‘5’
set interfaces vti vti1 ip ospf transmit-delay ‘1’
set interfaces vti vti1 mtu ‘1422’

set protocols ospf area 0 network ‘192.168.254.0/24’
set protocols ospf area 0 network ‘10.10.20.0/24′
set protocols ospf log-adjacency-changes ‘detail’
set protocols static route 0.0.0.0/0 next-hop 10.10.10.1 distance ‘1’
—-
set vpn ipsec esp-group ESP_AWS compression ‘disable’
set vpn ipsec esp-group ESP_AWS lifetime ‘3600’
set vpn ipsec esp-group ESP_AWS mode ‘tunnel’
set vpn ipsec esp-group ESP_AWS pfs ‘enable’
set vpn ipsec esp-group ESP_AWS proposal 1 encryption ‘aes256’
set vpn ipsec esp-group ESP_AWS proposal 1 hash ‘sha256’
set vpn ipsec ike-group IKE_AWS dead-peer-detection action ‘hold’
set vpn ipsec ike-group IKE_AWS dead-peer-detection interval ’30’
set vpn ipsec ike-group IKE_AWS dead-peer-detection timeout ‘120’
set vpn ipsec ike-group IKE_AWS lifetime ‘3600’
set vpn ipsec ike-group IKE_AWS proposal 1 dh-group ’14’
set vpn ipsec ike-group IKE_AWS proposal 1 encryption ‘aes256’
set vpn ipsec ike-group IKE_AWS proposal 1 hash ‘sha256’
set vpn ipsec ipsec-interfaces interface ‘eth0’
set vpn ipsec logging log-modes ‘all’
set vpn ipsec nat-traversal ‘enable’
set vpn ipsec site-to-site peer Global IP authentication mode ‘pre-shared-secret’
set vpn ipsec site-to-site peer Global IP authentication pre-shared-secret ‘aws’
set vpn ipsec site-to-site peer Global IP authentication remote-id ‘192.168.1.2’
set vpn ipsec site-to-site peer Global IP connection-type ‘respond’
set vpn ipsec site-to-site peer Global IP ike-group ‘IKE_BB’
set vpn ipsec site-to-site peer Global IP ikev2-reauth ‘inherit’
set vpn ipsec site-to-site peer Global IP local-address ‘10.200.10.50’
set vpn ipsec site-to-site peer Global IP vti bind ‘vti1’
set vpn ipsec site-to-site peer Global IP vti esp-group ‘ESP_BB’

トンネル張った後に, 「OSPFでネイバーがーーー」ってなったけどMTUサイズがあっていなかったから。合わせればState Fullになる。

AWS上のVyosと家のC841とでGRE over IPSecを試す

ちょっとやりたいことあってAWSとIPSec張りたいなと。

構成はこんな。

OSPFは別にいらないんだけど,折角なんでダイナミックルーティングをまわしてみる。

簡単にいけるかなーとも思ったけどかなりハマった。双方NAT配下で家のほうはさらにグローバルはDHCP割当で変わるわPATだからNAT-Tやらなきゃだとか,まーいろいろ気にするポイントがあった。

けど,無事につながりました。
大きくハマった点は以下2つ。

・CiscoのIPSec用ACLでgre指定だとNG。ip 指定で解消。
・Vyosのremote-idでCiscoの実IPを入れてあげる。

Vyosはわかるんだが,CiscoのACLはなんでだ。わからん・・・。

VTIとかでやればACL不要だからいいのかと思ったが,これはこれでハマったので又今度。

Try&Errorをひたすら試すはめになりました。
いい勉強させていただきました。

■ Cisco 抜粋
!
crypto isakmp policy 5
 encr aes 256
 hash sha256
 authentication pre-share
 group 14
 lifetime 3600
crypto isakmp key aws address A.A.A.A  255.255.255.255
crypto isakmp keepalive 30 30
!
!
crypto ipsec transform-set IPSEC esp-aes 256 esp-sha256-hmac 
 mode tunnel

!
!
crypto map GRE_IPSEC 10 ipsec-isakmp 
 set peer A.A.A.A
 set transform-set IPSEC 
 set pfs group14
 match address AWS_GRE
!
!
!
!
interface Loopback1
 ip address 172.16.1.1 255.255.255.255
!
interface Tunnel1
 ip address 192.168.254.1 255.255.255.0
 ip mtu 1400
 ip tcp adjust-mss 1360
 ip ospf network broadcast
 ip ospf hello-interval 5
 keepalive 5 3
 tunnel source Loopback1
 tunnel destination 172.16.1.2
!
interface Vlan100
 ip address 192.168.1.2 255.255.255.0
 ip virtual-reassembly in
 crypto map GRE_IPSEC
!
!
!
router ospf 1
 network 192.168.10.0 0.0.0.255 area 0
 network 192.168.254.0 0.0.0.255 area 0
!
!
ip access-list extended AWS_GRE
!
 permit ip host 172.16.1.1 host 172.16.1.2
■ Vyos 抜粋
set interfaces loopback lo address ‘172.16.1.2/32’
set interfaces tunnel tun1 address ‘192.168.254.2/24’
set interfaces tunnel tun1 encapsulation ‘gre’
set interfaces tunnel tun1 ip ospf dead-interval ’20’
set interfaces tunnel tun1 ip ospf hello-interval ‘5’
set interfaces tunnel tun1 ip ospf priority ‘1’
set interfaces tunnel tun1 ip ospf retransmit-interval ‘5’
set interfaces tunnel tun1 ip ospf transmit-delay ‘1’
set interfaces tunnel tun1 local-ip ‘172.16.1.2’
set interfaces tunnel tun1 mtu ‘1400’
set interfaces tunnel tun1 multicast ‘enable’
set interfaces tunnel tun1 remote-ip ‘172.16.1.1’
set protocols ospf area 0 network ‘192.168.254.0/24’
set protocols ospf area 0 network ‘10.10.20.0/24′
set protocols ospf log-adjacency-changes ‘detail’
set protocols static route 0.0.0.0/0 next-hop 10.10.10.1 distance ‘1’
—-
set vpn ipsec esp-group ESP_AWS compression ‘disable’
set vpn ipsec esp-group ESP_AWS lifetime ‘3600’
set vpn ipsec esp-group ESP_AWS mode ‘tunnel’
set vpn ipsec esp-group ESP_AWS pfs ‘enable’
set vpn ipsec esp-group ESP_AWS proposal 1 encryption ‘aes256’
set vpn ipsec esp-group ESP_AWS proposal 1 hash ‘sha256’
set vpn ipsec ike-group IKE_AWS dead-peer-detection action ‘hold’
set vpn ipsec ike-group IKE_AWS dead-peer-detection interval ’30’
set vpn ipsec ike-group IKE_AWS dead-peer-detection timeout ‘120’
set vpn ipsec ike-group IKE_AWS lifetime ‘3600’
set vpn ipsec ike-group IKE_AWS proposal 1 dh-group ’14’
set vpn ipsec ike-group IKE_AWS proposal 1 encryption ‘aes256’
set vpn ipsec ike-group IKE_AWS proposal 1 hash ‘sha256’
set vpn ipsec ipsec-interfaces interface ‘eth0’
set vpn ipsec logging log-modes ‘all’
set vpn ipsec nat-traversal ‘enable’
set vpn ipsec site-to-site peer 0.0.0.0 authentication mode ‘pre-shared-secret’
set vpn ipsec site-to-site peer 0.0.0.0 authentication pre-shared-secret ‘aws’
set vpn ipsec site-to-site peer 0.0.0.0 authentication remote-id ‘192.168.1.2’
set vpn ipsec site-to-site peer 0.0.0.0 connection-type ‘respond’
set vpn ipsec site-to-site peer 0.0.0.0 ike-group ‘IKE_AWS’
set vpn ipsec site-to-site peer 0.0.0.0 local-address ‘10.10.10.50’
set vpn ipsec site-to-site peer 0.0.0.0 tunnel 1 esp-group ‘ESP_AWS’
set vpn ipsec site-to-site peer 0.0.0.0 tunnel 1 local prefix ‘172.16.1.2/32’
set vpn ipsec site-to-site peer 0.0.0.0 tunnel 1 remote prefix ‘172.16.1.1/32’

備忘) AWSのFreeTrialなAMI

30日間過ぎたら自動で時間課金へ移行するとは書いてあったが, (勝手に)インスタンスを削除→再作成したらまた30日間お試しできると思っていたけど, AWS上で作成した時間を管理されているらしく, 30日間過ぎたらアウト。