在GRE隧道上配置基於預共享密鑰的IPsec

版權聲明:原創做品,容許轉載,轉載時請務必以超連接形式標明文章 原始出處 、做者信息和本聲明。不然將追究法律責任。 http://supercisco.blog.51cto.com/672109/309019
    基於IPsec僅支持單播和IP協議的局性性。對於組播、廣播和非IP流量的特性不能支持。那麼咱們能夠另外一種方式:使用GRE來封裝這些流量,再用IPsec加密這些感興趣流。使之經過GRE的隧道解決IPsec僅支持IP協議和單播的特性。但須要注意的是IPsec的隧道模式會破壞GRE的報頭,因此咱們必需要把它配置成傳輸模式。
  
1、下面經過一個實驗來看一下配置過程:
1、拓撲圖:
 
 
2、配置各路由器的 IP。而且在 R1R3上配置默認路由,以保證網絡的連通性:
R1(config)#ip route 0.0.0.0 0.0.0.0 202.102.48.66
 
R3(config)#ip route 0.0.0.0 0.0.0.0 211.64.135.33
R3#ping 202.102.48.65
 
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 202.102.48.65, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/29/80 ms
 
3、在 R1R3上配置隧道:
R1(config)#int tunnel 1 (建立隧道1)
R1(config-if)#ip unnumbered s1/1(爲節省IP借用s1/1物理接口地址)
R1(config-if)#tunnel source s1/1 (指定隧道的源)
R1(config-if)#tunnel destination 211.64.135.34 (指定目標隧道)
R1(config-if)#
*Mar  1 02:59:02.471: %LINEPROTO-5-UPDOWN: Line protocol on Interface Tunnel1, changed state to up  (配置以後也能看到R1up狀態)
 
R3(config-if)#ip unnumbered s1/0
R3(config-if)#tunnel source s1/0
R3(config-if)#tunnel destination 202.102.48.65
R3(config-if)#
*Mar  1 03:04:20.319: %LINEPROTO-5-UPDOWN: Line protocol on Interface Tunnel1, changed state to up
 
4R1R3隧道創建以後,寫一條靜態路由,確保兩端 loopback接口能夠通訊:
R1(config)#ip route 192.168.0.0 255.255.0.0 tunnel 1
 
R3(config)#ip route 172.16.0.0 255.255.0.0 tunnel 1
 
R3(config)#do ping 172.16.1.1
 
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 12/28/60 ms
R3(config)#
 
5、在 GRE隧道中,經過 IPsec加密這些感興趣流。爲使 GRE的報頭完整,下面在 R1R3上配置 IPsec的傳輸模式:
R1(config)#crypto isakmp key 0 CISCO address 211.64.135.34 (定義預共享密鑰)
R1(config)#crypto isakmp policy 1 (進入IKE策略編輯模式,1表明優先級)
R1(config-isakmp)#authentication pre-share使用預共享認證模式)
R1(config-isakmp)#encryption 3des (封裝3DES
R1(config-isakmp)#hash md5 (設置哈希算法爲MD5
R1(config-isakmp)#group 1 (使用Diffie-Hellman 1進行密鑰交換)
R1(config-isakmp)#lifetime 86400 (固然也能夠不寫這一條,由於86400秒是默認的生命週期)
R1(config-isakmp)#exit
R1(config)#crypto ipsec transform-set TEST esp-3des(配置IPsec的變換集,對數據交換進行加密)
R1(cfg-crypto-trans)#mode transport(爲確保GRE報頭的完整性,建議配置成傳輸模式)
R1(cfg-crypto-trans)#exit
R1(config)#access-list 100 per gre host 202.102.48.65 host 211.64.135.34(創建一個對GREACL
R1(config)#crypto map R1_GRE_R3 10 ipsec-isakmp (配置加密映射表)
R1(config-crypto-map)#set peer 211.64.135.34 (設置對等體IP
R1(config-crypto-map)#set transform-set TEST (引用以前設置的IPsec的變換集)
R1(config-crypto-map)#match address 100 (匹配ACL 100
R1(config-crypto-map)#int s1/1(進入須要掛接的接口)
R1(config-if)#crypto map R1_GRE_R3 (掛接映射表)
 
R3(config)#crypto isakmp key 0 CISCO address 202.102.48.65
R3(config)#crypto isakmp policy 1
R3(config-isakmp)#authentication pre-share
R3(config-isakmp)#encryption 3des
R3(config-isakmp)#group 1
R3(config-isakmp)#hash md5
R3(config-isakmp)#exit
R3(config)#crypto ipsec transform-set TEST esp-3des
R3(cfg-crypto-trans)#mode transport
R3(cfg-crypto-trans)#exit
R3(config)#access-list 100 permit gre host 211.64.135.34 host 202.102.48.65
R3(config)#crypto map R3_GRE_R1 10 ipsec-isakmp
R3(config-crypto-map)#set peer 202.102.48.65
R3(config-crypto-map)#set transform-set TEST
R3(config-crypto-map)#match address 100
R3(config-crypto-map)#int s1/0
R3(config-if)#crypto map R3_GRE_R1
R3(config-if)#
*Mar  1 05:11:19.770: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is ON  (配置完以後狀態爲on
 
2、驗證一下實驗的效果:
1、咱們用擴展 ping驗證一下 R1R3的迴環地址的通訊狀況:
R1#ping ip
Target IP address: 192.168.1.1
Repeat count [5]:
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]: y
Source address or interface: 172.16.1.1
Type of service [0]:
Set DF bit in IP header? [no]:
Validate reply data? [no]:
Data pattern [0xABCD]:
Loose, Strict, Record, Timestamp, Verbose[none]:
Sweep range of sizes [n]:
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
Packet sent with a source address of 172.16.1.1
.!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/41/84 ms
R1#
 
2、咱們能夠用 sh crypto isakmp sa 查看 IKE第一階段的協商信息,也能夠用 sh crypto ipsec sa來查看第二階段的安全關聯信息。上次實驗已經很詳細地分析了這些信息,這裏咱們只看一下 R1IKE會話信息:
R1#sh crypto session
Crypto session current status
 
Interface: Serial1/1 (本地的IPsec會話接口)
Session status: UP-ACTIVE   (狀態已經up
Peer: 211.64.135.34 port 500 (對等體的IP和端口號)
  IKE SA: local 202.102.48.65/500 remote 211.64.135.34/500 Active
  IPSEC FLOW: permit 47 host 202.102.48.65 host 211.64.135.34
        Active SAs: 2, origin: crypto map
本文出自 「 超越技術成就價值」 博客,請務必保留此出處 http://supercisco.blog.51cto.com/672109/309019
相關文章
相關標籤/搜索