今回はIPSecの設定をやってみようと思います。
これまで言葉は知っていて何となくの「L3での暗号化だよね?」ぐらいの知識しかありませんでした。以前GREの設定を行った際にIPSecと組み合わせて使うことが一般的ということを知ったので一度ちゃんと調べてみようと思った次第です。
結構ボリュームがあって理解するのが大変でしたが今までよりは理解が深まったようにも思います。
やることとしては、
1, ルータ2台にIPSecの設定をいれる
– トンネルモードで動作させる
2, ルータ1 / ルータ2 の間でIPSecトンネルを利用してペイロードが暗号化されていることを確認する
3, もろもろ確認

ルータ設定
###
### RT1
###
# 基本設定
Router>ena
Router#conf t
Router(config)#hostname RT1
# インターフェース設定
RT1(config)#int fastEthernet 0
RT1(config-if)#ip address 1.1.1.1 255.255.255.0
RT1(config-if)#no shutdown
RT1(config-if)#exit
RT1(config)#int fastEthernet 1
RT1(config-if)#ip address 192.168.10.1 255.255.255.0
RT1(config-if)#no shutdown
RT1(config-if)#exit
# IPSecの設定
### 多分IKEのやり取りをするさに必要となるパラメータっぽい
### pre-share をつかって、IKEで通信相手を認証する時に事前共有鍵で認証するようにしてる
RT1(config)#crypto isakmp policy 10
RT1(config-isakmp)#hash md5
RT1(config-isakmp)#authentication pre-share
RT1(config-isakmp)#exit
### IKEでSAを構築する際に相手を認証するための情報っぽい
RT1(config)#crypto isakmp key ipsec-test-user address 1.1.1.2
### SAで暗号化する際の有効なセキュリティプロトコルと、アルゴリズムの組み合わせを指定してるっぽい
RT1(config)#crypto ipsec transform-set ipsec-test-set esp-des esp-md5-hmac
RT1(cfg-crypto-trans)#exit
### SPD(セキュリティ・ポリシー・データベース)の内容っぽい
### 対象インターフェースに届いたパケットが、IPSecで暗号化する対象かを判断するために用いる情報っぽい
RT1(config)#crypto map ipsec-test-map 10 ipsec-isakmp
RT1(config-crypto-map)#set peer 1.1.1.2
RT1(config-crypto-map)#set transform-set ipsec-test-set
RT1(config-crypto-map)#match address 100
RT1(config-crypto-map)#exit
RT1(config)#access-list 100 permit ip 192.168.10.0 0.0.0.255 192.168.20.0 0.0.0.255
# IPSecの設定をインターフェースと紐付ける
RT1(config)#int fastEthernet 0
RT1(config-if)#crypto map ipsec-test-map
RT1(config-if)#exit
# デフォルトルートの設定
RT2(config)#ip route 0.0.0.0 0.0.0.0 1.1.1.2
RT2(config)#exit
RT1#write memory
###
### RT2
###
# 基本設定
RT1>ena
RT1#conf t
RT1(config)#hostname RT2
# インターフェース設定
RT2(config)#int fastEthernet 0
RT2(config-if)#ip address 1.1.1.2 255.255.255.0
RT2(config-if)#no shutdown
RT2(config-if)#exit
RT2(config)#int fastEthernet 1
RT2(config-if)#ip address 192.168.20.1 255.255.255.0
RT2(config-if)#no shutdown
RT2(config-if)#exit
# IPSecの設定
RT2(config)#crypto isakmp policy 10
RT2(config-isakmp)#hash md5
RT2(config-isakmp)#authentication pre-share
RT2(config-isakmp)#exit
RT2(config)#crypto isakmp key ipsec-test-user address 1.1.1.1
RT2(config)#crypto ipsec transform-set ipsec-test-set esp-des esp-md5-hmac
RT2(cfg-crypto-trans)#exit
RT2(config)#crypto map ipsec-test-map 10 ipsec-isakmp
RT2(config-crypto-map)#set peer 1.1.1.1
RT2(config-crypto-map)#set transform-set ipsec-test-set
RT2(config-crypto-map)#match address 100
RT2(config-crypto-map)#exit
RT2(config)#access-list 100 permit ip 192.168.20.0 0.0.0.255 192.168.10.0 0.0.0.255
# IPSecの設定をインターフェースと紐付ける
RT2(config)#int fastEthernet 0
RT2(config-if)#crypto map ipsec-test-map
RT2(config-if)#exit
# デフォルトルートの設定
RT2(config)#ip route 0.0.0.0 0.0.0.0 1.1.1.1
RT2(config)#exit
RT2#write memory
動作確認
PC1 –> PC2 にPINGを飛ばしてみます。IPSecがうまく設定できて入れば、途中経路でパケットを覗き見したときにIPペイロードが安吾浮かされているはずです。
$ ping -c 5 192.168.20.100
PING 192.168.20.100 (192.168.20.100): 56 data bytes
64 bytes from 192.168.20.100: icmp_seq=0 ttl=62 time=2.127 ms
64 bytes from 192.168.20.100: icmp_seq=1 ttl=62 time=2.126 ms
64 bytes from 192.168.20.100: icmp_seq=2 ttl=62 time=2.209 ms
64 bytes from 192.168.20.100: icmp_seq=3 ttl=62 time=2.249 ms
64 bytes from 192.168.20.100: icmp_seq=4 ttl=62 time=2.138 ms
--- 192.168.20.100 ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 2.126/2.170/2.249/0.050 ms
$
Pingが飛びました。IPペイロードも暗号化されていることが確認できました。
トンネルモードの動作で、新しくIPヘッダを付け替えてるので、送信元、宛先IPともにIPSecトンネルの終端装置になっていることが分かります。

まず、SA(セキュリティ・アソシエイト)の状態を確認します。
このSAが仮想的な経路とみなされて、暗号化されたデータがやり取りされる見たいです。TCPのセッション的な立ち位置っぽい。
RT1#show crypto isakmp sa
IPv4 Crypto ISAKMP SA
dst src state conn-id status
1.1.1.2 1.1.1.1 QM_IDLE 2001 ACTIVE
IPv6 Crypto ISAKMP SA
RT1#
RT1#show crypto ipsec sa
interface: FastEthernet0
Crypto map tag: ipsec-test-map, local addr 1.1.1.1
protected vrf: (none)
local ident (addr/mask/prot/port): (192.168.10.0/255.255.255.0/0/0)
remote ident (addr/mask/prot/port): (192.168.20.0/255.255.255.0/0/0)
current_peer 1.1.1.2 port 500
PERMIT, flags={origin_is_acl,}
#pkts encaps: 48, #pkts encrypt: 48, #pkts digest: 48
#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 1, #recv errors 0
local crypto endpt.: 1.1.1.1, remote crypto endpt.: 1.1.1.2
path mtu 1500, ip mtu 1500, ip mtu idb FastEthernet0
current outbound spi: 0x7A7452CC(2054443724)
PFS (Y/N): N, DH group: none
inbound esp sas:
spi: 0xF26ED36F(4067349359)
transform: esp-des esp-md5-hmac ,
in use settings ={Tunnel, }
conn id: 1, flow_id: Onboard VPN:1, sibling_flags 80000046, crypto map: ipsec-test-map
sa timing: remaining key lifetime (k/sec): (4572123/2632)
IV size: 8 bytes
replay detection support: Y
Status: ACTIVE
inbound ah sas:
inbound pcp sas:
outbound esp sas:
spi: 0x7A7452CC(2054443724)
transform: esp-des esp-md5-hmac ,
in use settings ={Tunnel, }
conn id: 2, flow_id: Onboard VPN:2, sibling_flags 80000046, crypto map: ipsec-test-map
sa timing: remaining key lifetime (k/sec): (4572118/2632)
IV size: 8 bytes
replay detection support: Y
Status: ACTIVE
outbound ah sas:
outbound pcp sas:
RT1#
よく確認すると、以下のとおり、inboundとoutboundでそれぞれSA(仮想的な経路)があることが分かります。IPSecでは行きと帰りで別々の経路を用意する必要があるみたいです。
### INBOUNDのSAを抜粋
inbound esp sas:
spi: 0xF26ED36F(4067349359)
transform: esp-des esp-md5-hmac ,
in use settings ={Tunnel, }
conn id: 1, flow_id: Onboard VPN:1, sibling_flags 80000046, crypto map: ipsec-test-map
sa timing: remaining key lifetime (k/sec): (4572123/2632)
IV size: 8 bytes
replay detection support: Y
Status: ACTIVE
### OUTBOUNDのSAを抜粋
outbound esp sas:
spi: 0x7A7452CC(2054443724)
transform: esp-des esp-md5-hmac ,
in use settings ={Tunnel, }
conn id: 2, flow_id: Onboard VPN:2, sibling_flags 80000046, crypto map: ipsec-test-map
sa timing: remaining key lifetime (k/sec): (4572118/2632)
IV size: 8 bytes
replay detection support: Y
Status: ACTIVE
それぞれ、SPIの値が設定されています。SPIはSAのデータベース(SAD)から対象のパケットがどのSAで復号する必要があるかを検索するときに利用するキーのようなものだと理解しています。(ちゃんとあってるかは微妙)そのため、ESPヘッダの中にもSPIが入っていることが確認できます。
(OUTBOUND: 1.1.1.1 –> 1.1.1.2)※Pingを打ったときの行きパケット
SPI : 0x7A7452CC

SPI : 0xF26ED36F

1, SPD(セキュリティポリシーDB)にマッチしたパケットを検知(IPSecで暗号化する:PROTECT)
2, SADを検索して送信元IP/宛先IPにマッチするSAがあるかを検索する
3, 初回でSAが生成されてないので、IKEを使って、LocalルータとRemoteルータにそれぞれSAを作成する
4, SAの暗号ポリシーにしたがってIPペイロードを暗号化する
– 暗号化で利用する共通鍵などはIKEで設定されたものを利用する
5, Remoteルータからの戻りの際も戻りようのSAを構築するので、「3, 4,」のSA構築作業がRemoteルータでもう一度行われる
以上で今回の動作確認は終わりたいとおもいます。
いままで、トンネルモードとトランスポートモードの違いもいまいち理解してませんでしたが今回の設定を通して何となくですが理解することができたように思います。
IKEの細かいシーケンスの確認やGRE over IPSec の設定なんかもまたそのうちやってみようかとおもいます。
それではまた。
参考:
http://www5e.biglobe.ne.jp/aji/3min/ex/sup21.html
https://www.cisco.com/c/ja_jp/support/docs/routers/1700-series-modular-access-routers/71462-rtr-l2l-ipsec-split.html
https://www.cisco.com/c/ja_jp/support/docs/security-vpn/ipsec-negotiation-ike-protocols/5409-ipsec-debug-00.html