實驗目的: 1).通過配置IPSEC、GRE和NAT技術,讓我們對IPSEC和NAT的工作原理有更深的瞭解
2).掌握IPSEC的配置方法,對它在網絡上的應用有更深的瞭解
實驗要求: 1).知道IPSEC與NAT之間衝突問題,知道該如何解決.
實驗內容: 1).在同一臺路由器上配置IPSEC和NAT技術,IPSEC流量從GRE tunnel上走。
一、配置路由器的地址
R1:
R1(config)#int s1/0
R1(config-if)#ip add 199.1.1.1 255.255.255.0
R1(config-if)#clock rate 64000
R1(config-if)#no sh
R1(config)#int f0/0
R1(config-if)#ip add 172.16.1.1 255.255.255.0
R1(config-if)#no sh
R1(config)#ip route 0.0.0.0 0.0.0.0 199.1.1.2 //配置靜態默認路由,使得內網能夠連通外網
R2:
R2(config)#int s0/0
R2(config-if)#ip add 199.1.1.2 255.255.255.0
R2(config-if)#no sh
R2(config)#int s0/1
R2(config-if)#ip add 200.1.1.1 255.255.255.0
R2(config-if)#clock rate 64000
R2(config-if)#no sh
R3:
R3(config)#int s0/0
R3(config-if)#ip add 200.1.1.2 255.255.255.0
R3(config-if)#no sh
R3(config)#int s0/1
R3(config-if)#ip add 201.1.1.1 255.255.255.0
R3(config-if)#clock rate 64000
R3(config-if)#no sh
R4:
R4(config)#int s1/0
R4(config-if)#ip add 201.1.1.2 255.255.255.0
R4(config-if)#no sh
R4(config)#int f0/0
R4(config-if)#ip add 172.17.1.1 255.255.255.0
R4(config-if)#no sh
R4(config)#ip route 0.0.0.0 0.0.0.0 201.1.1.1 //配置靜態默認路由,使得內網能夠連通外網
配置好以後,可以在特權模式下使用“ show ip interface brief ”來查看路由器的接口信息,這裏本人不再演示!!
二、配置動態路由協議(OSPF),在R2和R3上配置
R2:
R2(config)#router ospf 100
R2(config-router)#net 199.1.1.0 0.0.0.255 area 0
R2(config-router)#net 200.1.1.0 0.0.0.255 area 0
R3:
R3(config)#router ospf 100
R3(config-router)#net 200.1.1.0 0.0.0.255 area 0
R3(config-router)#net 201.1.1.0 0.0.0.255 area 0
配置好以後,可以在特權模式下使用“ show ip route ”來查看路由器的路由表,這裏本人不再演示!!
三、配置GRE:
R1:
R1(config)# interface tunnel 1
R1(config-if)# tunnel source s1/0
R1(config-if)# tunnel destination 201.1.1.2
R1(config-if)# ip add 1.1.1.1 255.255.255.0
R1(config-if)# no shut
R4:
R4(config)# interface tunnel 1
R4(config-if)# tunnel source s1/0
R4(config-if)# tunnel destination 199.1.1.1
R4(config-if)# ip add 1.1.1.2 255.255.255.0
R4(config-if)# no shut
四、在GRE裏做RIPv2
R1:
R1(config)#router rip
R1(config-router)#ver 2
R1(config-router)#no auto-summary
R1(config-router)#net 1.1.1.0 //宣告直連的網絡,這裏的1.1.1.0
R1(config-router)#net 172.16.1.0 是tunnel 1裏的路由,172.16.1.0是內網路由
R4:
R4(config)#router rip
R4(config-router)#ver 2
R4(config-router)#no auto-summary
R4(config-router)#net 1.1.1.0 宣告直連的網絡,這裏的1.1.1.0
R4(config-router)#net 172.17.1.0 是tunnel 1裏的路由,172.17.1.0是內網裏的!
說明:有關GRE的其他配置在這裏就不詳細說明,這裏就簡單演示配置命令!!
四、配置IKE IPSEC ***
R1:
1.配置IPsec策略協商:
R1(config)#crypto isakmp enable //啓動IKE的協議
R1(config)#crypto isakmp policy 1 //建立IKE的協商策略,“1爲優先級,值越小越優先”
R1(config-isakmp)#encryption des //加密算法爲des
R1(config-isakmp)#hash md5 //認證算法爲md5
R1(config-isakmp)#authentication pre-share //身份驗證爲“預共享密鑰”
R1(config-isakmp)#lifetime 60 //每60秒發送一次hello包,保持連通性
R1(config-isakmp)#group 1
2.配置IKE的與共享密鑰,與對端IP地址
R1(config)#crypto isakmp key 0 kfp address 201.1.1.2 //設置共享密鑰和對端地址
3.配置IPSEC 轉換集(IPSEC 策略的安全提議)
R1(config)#crypto ipsec transform-set aa esp-des esp-md5-hmac
// aa是轉換集的名字,esp-des表示用des加密算法,esp-md5-hmac表示用sha算法驗證
R1(cfg-crypto-tran)#mode tunnel //IPSEC的工作模式是tunnel
4.配置IPSEC保護的數據流(保護對象)(ACL)
R1(config)#access-list 102 permit ip 172.16.1.0 0.0.0.255 172.17.1.0 0.0.0.255
5.配置IPSEC策略
R1(config)# crypto map aamap 10 ipsec-isakmp
R1(config-crypto-map)#match address 102 //它的保護對象是acl 102中定義的
R1(config-crypto-map)#set peer 201.1.1.2 //對等體(對端IP地址)爲201.1.1.2
R1(config-crypto-map)#set transform-set aa //調用轉換集aa
6.將策略應用到接口
R1(config)#int tunnel 1
R1(config-if)#crypto map aamap
R4:
R4(config)#crypto isakmp enable //啓動IKE的協議
R4(config)#crypto isakmp policy 1 //建立IKE的協商策略,“1爲優先級,值越小越優先”
R4(config-isakmp)#encryption des //加密算法爲des
R4(config-isakmp)#hash md5 //認證算法爲md5
R4(config-isakmp)#authentication pre-share 身份驗證爲“預共享密鑰”
R4(config-isakmp)#lifetime 60 //每60秒發送一次hello包,保持連通性
R4(config-isakmp)#group 1
2.配置IKE的與共享密鑰,與對端IP地址
R4(config)#crypto isakmp key 0 kfp address 199.1.1.1 //設置共享密鑰和對端地址
3.配置IPSEC 轉換集(IPSEC 策略的安全提議)
R4(config)#crypto ipsec transform-set bb esp-des esp-md5-hmac
// bb是轉換集的名字,esp-des表示用des加密算法,esp-md5-hmac表示用sha算法驗證
R4(cfg-crypto-tran)#mode tunnel //IPSEC的工作模式是tunnel
4.配置IPSEC保護的數據流(保護對象)(ACL)
R4(config)#access-list 102 permit ip 192.168.3.0 0.0.0.255 192.168.1.0 0.0.0.255
5.配置IPSEC策略
R4(config)# crypto map bbmap 10 ipsec-isakmp
R4(config-crypto-map)#match address 102 //它的保護對象是acl 102中定義的
R4(config-crypto-map)#set peer 199.1.1.1 //對等體(對端IP地址)爲199.1.1.1
R4(config-crypto-map)#set transform-set bb //調用轉換集bb
6.將策略應用到接口
R4(config)# int tunnel 1
R4(config-if)#crypto map bbmap
說明:在這裏,我們結合GRE和IPSEC的配置來看,在這裏實驗目的很明確,要做NAT和IPSEC技術,而兩者是相互衝突的,解決方法是將IPSEC放入GRE tunnel裏進行傳輸,在路由器的物理接口上做NAT技術,這樣,兩者就能共存,互不干擾,而將IPSEC放入到GRE tunnel裏,就涉及到GRE和IPSEC的配置先後問題,本實驗是先做GRE,後做IPSEC,是將IPSEC ***放入GRE tunnel裏進行傳輸
這時候,172.16.1.0內網裏的主機和172.17.1.0內網裏的主機是能相互Ping通的
五、驗證:
PC1:172.16.1.2 172.16.1.1 255.255.255.0
//PC1的ip地址是172.16.1.2,網關是172.16.1.1,子網掩碼是255.255.255.0
PC2: 172.17.1.1 172.16.1.1 255.255.255.0
//PC2的ip地址是172.17.1.2,網關是172.17.1.1,子網掩碼是255.255.255.0
PC1(172.16.1.2) ping PC2(172.17.1.2)結果如下:
PC2(172.17.1.2) ping PC1(172.16.1.2)結果如下:
此時內網主機雖然能相互訪問,但是還不能訪問Internet,要想能正常訪問Internet,還要做NAT
技術!!
六、配置NAT技術(PAT)
R1:
R1(config)#access-list 1 permit 172.16.1.0 0.0.0.255
R1(config)#ip nat inside source list 1 interface s1/0 overload
R1(config)#int f0/0
R1(config-if)#ip nat inside
R1(config-if)#int s1/0
R1(config-if)#ip nat outside
R4(config)#access-list 1 permit 172.17.1.0
R4(config)#ip nat inside source list 1 interface s1/0 overload
R4(config)#int f0/0
R4(config-if)#ip nat inside
R4(config-if)#int s1/0
R4(config-if)#ip nat outside
七、驗證:
內網主機能ping通公網上的主機或ip地址:
用PC1 ping 公網地址(200.1.1.1):結果如下:
用PC2 ping 公網地址(200.1.1.1):結果如下:
上圖說明內網主機能ping通公網上的主機或公網ip地址。
結合上面IPSEC的驗證結果,說明NAT和IPSEC可以在同一臺路由器上配置,實現內網主機既能通過***來訪問其它內網主機,也能訪問Internet!!
實驗完成!!!
此實驗在小凡模擬器上完成,需要IOS的網友請加Q:821972656
謝謝支持!!!