目錄
前言
越來越多公司用 IPSEC 來建立 Site to Site VPN,普遍應用於透過 Internet 建立連線,因為價錢便宜,設定上相對簡單得多。IPSEC VPN 用 IKE (Internet Key Exchange) 進行參數交換和建立連線,因此在設定 IPSEC VPN 前應先了解 IKE 的運作。
IKE (Internet Key Exchange)
IKE 又分為 Phase 1 和 Phase 2,現在來看看 Phase 1 和 Phase 2 分別做了些什麼。
Phase 1
IKE Phase 1 的工作主要是認證 (authenticate) 對方,什麼是認證呢?很簡單,我是 Site A 的 Router,你說你是 Site B 的 Router 想和我建立 VPN,我怎知道你真的是 Site B 而不是其他公司呢?其中一個常用的方法是用 Share Secret 來認證,即是說 Site A 和 Site B 的 Router 都知道同一組密碼,證明是自己人,就通過認證了。另外,Phase 1 還會用透過 Diffie-Hellman 來建立一組 Key,這組 Key 是用來為 Phase 2 的資訊進行加密,即是說 Phase 1 的工作就是為 Phase 2 準備一條加密管道,讓 Phase 2 用這條管道去交換資訊。
Phase 2
至於 Phase 2 則是真正建立 IPSEC VPN 管道讓資訊在這條管道上傳送。記著 Phase 2 是建立在 Phase 1 之上的,沒有 Phase 1 就沒有 Phase 2。
設定
現在我們試為以下網絡的 Site A 和 Site B 設定 Site to Site IPSEC VPN。
Router 的起始設定如下:
hostname R1 ! interface Ethernet0/0 ip address 192.168.13.1 255.255.255.0 ! interface Ethernet0/1 ip address 192.168.10.1 255.255.255.0 ! ip route 0.0.0.0 0.0.0.0 192.168.13.3
hostname R2 ! interface Ethernet0/0 ip address 192.168.23.2 255.255.255.0 ! interface Ethernet0/1 ip address 192.168.20.1 255.255.255.0 ! ip route 0.0.0.0 0.0.0.0 192.168.23.3
hostname R3 ! interface Ethernet0/0 ip address 192.168.13.3 255.255.255.0 ! interface Ethernet0/1 ip address 192.168.23.3 255.255.255.0
所以,R1 能夠 Ping 通 192.168.23.2,但就去不到 192.168.20.1,因為我們假設 192.168.10.0 / 24 和 192.168.20.0 / 24 都是 Internal IP。
R1#ping 192.168.23.2 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.23.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 24/49/92 ms R1# R1#ping 192.168.20.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.20.1, timeout is 2 seconds: UUUUU Success rate is 0 percent (0/5)
Step 1: 設定 Interesting Traffic
所謂 Interesting Traffic 就是需要建立 VPN 的 Traffic,在本例子中,R1 的 Interesting Traffic 就是由 192.168.10.0 / 24 到 192.168.20.0 / 24 的 Traffic,而 R2 則剛好相反,是由 192.168.20.0 / 24 到 192.168.10.0 / 24,我們用 Access List 把這些 Traffic Define 好。
R1(config)#ip access-list extended VPN-Traffic R1(config-ext-nacl)#permit ip 192.168.10.0 0.0.0.255 192.168.20.0 0.0.0.255 R1(config-ext-nacl)#exit
R2(config)#ip access-list extended VPN-Traffic R2(config-ext-nacl)#permit ip 192.168.20.0 0.0.0.255 192.168.10.0 0.0.0.255 R2(config-ext-nacl)#exit
Step 2: 設定 IKE Phase 1 參數
R1(config)#crypto isakmp policy 1 !encryption 可使用 DES, 3DES 或 AES,其中以 AES Security 最高 R1(config-isakmp)#encryption aes !hash 可選 SHA 或 MD5,SHA Security 較高 R1(config-isakmp)#hash md5 !用 Pre Share Key 的方法來認證對方 R1(config-isakmp)#authentication pre-share !DH Group 用作產生 Symmetric Key,一般使用 Group 2 R1(config-isakmp)#group 2 !管道的 Lifetime,預設為 86400 R1(config-isakmp)#lifetime 30000
R2(config)#crypto isakmp policy 1 R2(config-isakmp)#encryption aes R2(config-isakmp)#hash md5 R2(config-isakmp)#authentication pre-share R2(config-isakmp)#group 2 R2(config-isakmp)#lifetime 30000
Step 3: 設定 IKE Phase 2 參數
可以在 AH Transform 選擇一款,在 ESP Cipher 選擇一款,在 ESP Auth 選擇一款,基本上選用越多就越安全但比較耗資源。最後選擇是否要做 Compression。所以最多可選 4 個 Option。無論選多少個,兩邊 Peer 的選擇必需相同。
R1(config)#crypto ipsec transform-set TS ? ah-md5-hmac AH-HMAC-MD5 transform ah-sha-hmac AH-HMAC-SHA transform comp-lzs IP Compression using the LZS compression algorithm esp-3des ESP transform using 3DES(EDE) cipher (168 bits) esp-aes ESP transform using AES cipher esp-des ESP transform using DES cipher (56 bits) esp-md5-hmac ESP transform using HMAC-MD5 auth esp-null ESP transform w/o cipher esp-seal ESP transform using SEAL cipher (160 bits) esp-sha-hmac ESP transform using HMAC-SHA auth
R1(config)#crypto ipsec transform-set TS esp-3des ah-sha-hmac
R2(config)#crypto ipsec transform-set TS esp-3des ah-sha-hmac
假設以 ccie 為 Pre-share Key。
R1(config)#crypto isakmp key 6 ccie address 192.168.23.2
R2(config)#crypto isakmp key 6 ccie address 192.168.13.1
Step 5: 定義 Crypto Map
把我們剛才設定的東西,一次過放進 Crypto Map 之中。最後把 Crypto Map 放上 Interface。
R1(config)#crypto map CMAP 1 ipsec-isakmp % NOTE: This new crypto map will remain disabled until a peer and a valid access list have been configured. R1(config-crypto-map)#set peer 192.168.23.2 R1(config-crypto-map)#set transform-set TS R1(config-crypto-map)#match address VPN-Traffic R1(config-crypto-map)#exit R1(config)#interface ethernet 0/0 R1(config-if)#crypto map CMAP
R2(config)#crypto map CMAP 1 ipsec-isakmp % NOTE: This new crypto map will remain disabled until a peer and a valid access list have been configured. R2(config-crypto-map)#set peer 192.168.13.1 R2(config-crypto-map)#set transform-set TS R2(config-crypto-map)#match address VPN-Traffic R2(config-crypto-map)#exit R2(config)#interface ethernet 0/0 R2(config-if)#crypto map CMAP
測試
在 R1 嘗試讓 192.168.10.1 去 Ping 192.168.20.1,已經可以 Ping 通了。
R1#ping 192.168.20.1 source 192.168.10.1 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 192.168.20.1, timeout is 2 seconds: Packet sent with a source address of 192.168.10.1 .!!!! Success rate is 80 percent (4/5), round-trip min/avg/max = 36/72/96 ms R1#show crypto isakmp sa dst src state conn-id slot status 192.168.23.2 192.168.13.1 QM_IDLE 1 0 ACTIVE R1#show crypto ipsec sa interface: Ethernet0/0 Crypto map tag: CMAP, local addr 192.168.13.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 192.168.23.2 port 500 PERMIT, flags={origin_is_acl,} #pkts encaps: 4, #pkts encrypt: 4, #pkts digest: 4 #pkts decaps: 4, #pkts decrypt: 4, #pkts verify: 4 #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.: 192.168.13.1, remote crypto endpt.: 192.168.23.2 path mtu 1500, ip mtu 1500, ip mtu idb Ethernet0/0 current outbound spi: 0xD2E73BB1(3538369457) inbound esp sas: spi: 0x80CE4FB7(2161004471) transform: esp-3des , in use settings ={Tunnel, } conn id: 2001, flow_id: SW:1, crypto map: CMAP sa timing: remaining key lifetime (k/sec): (4531862/3488) IV size: 8 bytes replay detection support: Y Status: ACTIVE inbound ah sas: spi: 0x490FFB61(1225784161) transform: ah-sha-hmac , in use settings ={Tunnel, } conn id: 2001, flow_id: SW:1, crypto map: CMAP sa timing: remaining key lifetime (k/sec): (4531862/3481) replay detection support: Y Status: ACTIVE inbound pcp sas: outbound esp sas: spi: 0xD2E73BB1(3538369457) transform: esp-3des , in use settings ={Tunnel, } conn id: 2002, flow_id: SW:2, crypto map: CMAP sa timing: remaining key lifetime (k/sec): (4531862/3481) IV size: 8 bytes replay detection support: Y Status: ACTIVE outbound ah sas: spi: 0x4F72667D(1332897405) transform: ah-sha-hmac , in use settings ={Tunnel, } conn id: 2002, flow_id: SW:2, crypto map: CMAP sa timing: remaining key lifetime (k/sec): (4531862/3479) replay detection support: Y Status: ACTIVE outbound pcp sas:
相關主題
Jan Ho 2014-11-24
Posted In: 虛擬私人網路 VPN
發佈留言