中小型企业组网,GRE over IPsec项目实例

项目背景:

公司总部和分部之间想要组网,传输ERP数据,要求数据传输是加密的;

总部网段:192.168.0.0/16

分公司网段:172.16.0.0/16

 

网络拓扑:

拓扑说明:

R2,R3分别为Site1,Site2的边界路由器,连接到ISP供应商;

Site1有三个部门,划分3个VLAN;

Site2有两个部门,划分2个VLAN;

R2,R3之间先建立IPsec VP N再建立GRE通道;

R2,R3,R4,R5之间运行OSPF协议;

配置:

1. 配置各路由器端口IP地址,使相邻路由器相互ping通
R1:
R1(config)#int e1/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 e1/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 e1/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 e1/1
R2(config-if)#ip address 192.168.0.1 255.255.255.0
R2(config-if)#no shutdown
R2(config-if)#exit
R2(config)#int loopback0
R2(config-if)#ip address 2.2.2.2 255.255.255.0
R2(config-if)#exit
 
R3:
R3(config)#int e1/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 e1/1
R3(config-if)#ip address 172.16.0.1 255.255.255.0
R3(config-if)#no shutdown
R3(config-if)#exit
R3(config)#int loopback0
R3(config-if)#ip address 3.3.3.3 255.255.255.0
R3(config-if)#exit
 
R4:
R4(config)#int e1/3
R4(config-if)#ip address 192.168.0.254 255.255.255.0
R4(config-if)#no shutdown
R4(config-if)#exit
 
R5:
R5(config)#int e1/3
R5(config-if)#ip address 172.16.0.254 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 2.2.2.0 0.0.0.255 3.3.3.0 0.0.0.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 e1/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 3.3.3.0 0.0.0.255 2.2.2.0 0.0.0.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 e1/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 VP N配置完毕,我们来ping一下试试:

ping成功,我们接下来配置GRE通道。

3. 在R2、R3之间建立GRE通道
R2:
R2(config)#int tunnel 0				//创建通道0
	*Mar  1 00:15:50.263: %LINEPROTO-5-UPDOWN: Line protocol on Interface Tunnel0, changed state to down
R2(config-if)#tunnel source 2.2.2.2		//通道的源ip
R2(config-if)#tunnel destination 3.3.3.3	//通道的目标ip,此时如果源ip和目标ip之间能正常通信时,通道UP
	*Mar  1 00:16:57.287: %LINEPROTO-5-UPDOWN: Line protocol on Interface Tunnel0, changed state to up
R2(config-if)#tunnel mode gre ip
R2(config-if)#ip address 10.1.1.2 255.255.255.0	//通道的两端必须在同一网段,逻辑上能互通
R2(config-if)#exit
R2(config)#ip route 192.168.0.0 255.255.0.0 tunnel 0	//指定192.168.0.0网段的流量走通道0
 
R3:
R3(config)#int tunnel 0				//创建通道0
	*Mar  1 00:15:50.263: %LINEPROTO-5-UPDOWN: Line protocol on Interface Tunnel0, changed state to down
R3(config-if)#tunnel source 3.3.3.3		//通道的源ip
R3(config-if)#tunnel destination 2.2.2.2	//通道的目标ip,此时如果源ip和目标ip之间能正常通信时,通道UP
	*Mar  1 00:16:57.287: %LINEPROTO-5-UPDOWN: Line protocol on Interface Tunnel0, changed state to up
R3(config-if)#tunnel mode gre ip
R3(config-if)#ip address 10.1.1.3 255.255.255.0	//通道的两端必须在同一网段,逻辑上能互通
R3(config-if)#exit
R3(config)#ip route 172.16.0.0 255.255.0.0 tunnel 0	//指定172.16.0.0网段的流量走通道0
 
4. 在R2、R3、R4、R5之间配置OSPF协议
R2:
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 10.1.1.0 0.0.0.255 area 0
R2(config-router)#network 192.168.0.0 0.0.0.255 area 1
R2(config-router)#exit
 
R3:
R3(config)#router ospf 1
R3config-router)#router-id 3.3.3.3
R3(config-router)#network 10.1.1.0 0.0.0.255 area 0
R3(config-router)#network 172.1.0.0 0.0.0.255 area 2
R3(config-router)#exit
 
R4:
R4(config)#router ospf 1
R4config-router)#router-id 4.4.4.4
R4(config-router)#network 192.168.0.0 0.0.0.255 area 1
R4(config-router)#exit
R4(config)#ip route 172.16.0.0 255.255.0.0 10.1.1.2	//指定去往172.16.0.0网段的流量下一跳为10.1.1.2(GRE通道)
 
R5:
R5(config)#router ospf 1
R5config-router)#router-id 5.5.5.5
R5(config-router)#network 172.16.0.0 0.0.0.255 area 2
R5(config-router)#exit
R5(config)#ip route 192.168.0.0 255.255.0.0 10.1.1.3	//指定去往192.168.0.0网段的流量下一跳为10.1.1.3(GRE通道)

至此GRE通道配置完成,我们来测试一下Site1 ping Site2试试:

测试成功。

有人可能会有疑问说,就两台路由器为啥要用OSPF协议呢,直接用静态路由不可以吗?

其实如果你更喜欢静态路由也行,只是我们站在网络架构的角度考虑的话,以后如果公司壮大,需要用到更多的路由,我们就可以不必再重新设计网络拓扑了,在原有的拓扑上加路由器,配路由协议就行。

 

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

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