Cisco思科路由器配置IPsec,建立Site to Site项目实例

项目背景:

最近做的一个项目中需要总公司和分公司之间内网互通;

总公司内网段:192.168.0.0/16

分公司内网段:172.16.0.0/16

考虑到专线的成本问题,最后公司决定使用IPsec。

 

简化网络拓扑:

配置:

1. 配置各路由器端口IP地址,使相邻路由器相互ping通
R1:
R1(config)#int e0/0
R1(config-if)#ip address 12.1.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit
R1(config)#int e0/1
R1(config-if)#ip address 13.1.1.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#exit

R2:
R2(config)#int e0/0
R2(config-if)#ip address 12.1.1.2 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#int e0/1
R2(config-if)#ip address 192.168.2.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#int loopback0
R2(config-if)#ip address 192.168.1.1 255.255.255.0
R2(config-if)#exit

R3:
R3(config)#int e0/0
R3(config-if)#ip address 13.1.1.3 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#int e0/1
R3(config-if)#ip address 172.16.2.1 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#int loopback0
R3(config-if)#ip address 172.16.1.1 255.255.255.0
R3(config-if)#exit

R4:
R4(config)#int e0/0
R4(config-if)#ip address 192.168.2.2 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#exit

R5:
R5(config)#int e0/0
R5(config-if)#ip address 172.16.2.2 255.255.255.0
R5(config-if)#no shutdown
R5(config-if)#exit

2. 在R2、R3之间配置IPsec VPN,在环回接口之间建立连接
R2:
//配置感兴趣流,使Site1内网的流量能够通过该路由器到Site2
R2(config)#access-list 100 permit ip 192.168.0.0 0.0.255.255 172.16.0.0 0.0.255.255
R2(config)#crypto isakmp policy 10		//配置加密策略
R2(config-isakmp)#encryption 3des
R2(config-isakmp)#hash md5
R2(config-isakmp)#authentication pre-share
R2(config-isakmp)#group 2
R2(config-isakmp)#crypto isakmp key 6 cisco123 address 13.1.1.3		//密钥为cisco123,13.1.1.3为对端连接ISP的外网IP地址
R2(config)#crypto ipsec transform-set xxx esp-3des esp-md5-hmac
R2(cfg-crypto-trans)#mode tunnel		//site-to-site使用tunnel模式
R2(cfg-crypto-trans)#crypto map linktosite 10 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 transform-set xxx
R2(config-crypto-map)#set peer 13.1.1.3		//对等体IP
R2(config-crypto-map)#match address 100		//匹配的感兴趣流为ACL 100
R2(config-crypto-map)#int e0/0			//将设置好的加密图应用到接口e0/0上
R2(config-if)#crypto map linktosite
	*Mar  1 00:12:00.439: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is ON
R2(config-if)#exit
R2(config)ip route 0.0.0.0 0.0.0.0 12.1.1.1	//该路由器的所有流量下一跳为12.1.1.1

R3:
//配置感兴趣流,使Site2内网的流量能够通过该路由器到Site1
R3(config)#access-list 100 permit ip 172.16.0.0 0.0.255.255 192.168.0.0 0.0.255.255
R3(config)#crypto isakmp policy 10		//配置加密策略
R3(config-isakmp)#encryption 3des
R3(config-isakmp)#hash md5
R3(config-isakmp)#authentication pre-share
R3(config-isakmp)#group 2
R3(config-isakmp)#crypto isakmp key 6 cisco123 address 12.1.1.2		//密钥为cisco123,13.1.1.3为对端连接ISP的外网IP地址
R3(config)#crypto ipsec transform-set xxx esp-3des esp-md5-hmac
R3(cfg-crypto-trans)#mode tunnel		//site-to-site使用tunnel模式
R3(cfg-crypto-trans)#crypto map linktosite 10 ipsec-isakmp
	% NOTE: This new crypto map will remain disabled until a peer
        and a valid access list have been configured.
R3(config-crypto-map)#set transform-set xxx
R3(config-crypto-map)#set peer 12.1.1.2		//对等体IP
R3(config-crypto-map)#match address 100		//匹配的感兴趣流为ACL 100
R3(config-crypto-map)#int e0/0			//将设置好的加密图应用到接口e0/0上
R3(config-if)#crypto map linktosite
	*Mar  1 00:12:00.439: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is ON
R3(config-if)#exit
R3(config)ip route 0.0.0.0 0.0.0.0 13.1.1.1	//该路由器的所有流量下一跳为13.1.1.1

至此IPsec配置完成,我们来用环回地址相互ping一下试试:

IPsec的建立需要流量的触发,如果ping不通,多试一次,对端也相互ping一下。

但是你以为就配置完了吗?哈哈哈,这时我们在R3上ping192.168.2.2发现是不通的,接下来我们继续。

3. Site1、Site2分别配置OSPF路由协议
Site1:
R2:
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 192.168.1.0 0.0.0.255 area 0
R2(config-router)#network 192.168.2.0 0.0.0.255 area 0
R2(config-router)#exit

R4:
R4(config)#router ospf 1
R4(config-router)#router-id 4.4.4.4
R4(config-router)#network 192.168.2.0 0.0.0.255 area 0
R4(config-router)#exit
R4(config)#ip route 172.16.0.0 255.255.0.0 192.168.1.1		//所有到172.16.0.0网段的流量下一跳为192.168.1.1

Site2:
R3:
R3(config)#router ospf 1
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 172.16.1.0 0.0.0.255 area 0
R3(config-router)#network 172.16.2.0 0.0.0.255 area 0
R3(config-router)#exit

R5:
R3(config)#router ospf 1
R3(config-router)#router-id 5.5.5.5
R3(config-router)#network 172.16.2.0 0.0.0.255 area 0
R5(config-router)#exit
R5(config)#ip route 192.168.0.0 255.255.0.0 172.16.1.1		//所有到192.168.0.0网段的流量下一跳为172.16.1.1

我们在R4上ping R5内网试试:

测试成功。

 

后记:

在配置IPsec时我的体会:一定要清楚流量的流向,源IP和目标IP,发现ping不通时,多检查路由表,想清楚下一跳的关系。

为什么使用环回接口配置IPsec呢?

因为环回接口有物理接口不具备的稳定性呀。

 

参考资料:

IPSec 理论知识:https://blog.csdn.net/bingyu9875/article/details/61614797

配置命令:https://blog.csdn.net/mizong/article/details/89341039?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

 

本文原创,转载请注明出处

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章