需求分析:
由于IPSec不支持对多播和广播数据包的加密,这样的话,使用IPSec的隧道中,动态路由协议等依靠多播和广播的协议就不能进行正常通告,所以,这时候要配合GRE隧道,GRE隧道会将多播和广播数据包封装到单播包中,再经过IPSec加密。

此外由于GRE建立的是简单的,不进行加密的×××隧道,他通过在物理链路中使用ip地址和路由穿越普通网络。所以很常见的方法就是使用IPSec对GRE进行加密,提供数据安全保证
 
更正:拓扑图上的R3的LOOPBCAK地址为192.168.0.3/32

配置GRE

RT1:

 interface Serial1/0

 ip address 200.200.200.1 255.255.255.252

 no shutdown

interface Loopback0

 ip address 192.168.0.1 255.255.255.255

 no shutdown

interface Ethernet0/0

 ip address 192.168.10.1 255.255.255.0

 no shutdown

 int tunnel 0                       //建立TUNNEL口

 ip address 192.168.1.1 255.255.255.0

 no shutdown

 tunnel mode gre ip          //TUNNEL口的类型为GRE,默认

 tunnel source 200.200.200.1     //指定TUNNEL的源

 tunnel destination 202.202.202.2  //指定TUNNEL的目标

 ip route 0.0.0.0 0.0.0.0 s1/0    //去往公网的缺省路由

router ospf 1          //总部与分部之间使用OSPF(GRE支持组播或多播,所以能够使用动态路由协议)

 router-id 192.168.0.1

 passive-interface Serial1/0//不能发布公网的路由,否则会出现down又UP

 network 192.168.0.1 0.0.0.0 area 0

 network 192.168.1.0 0.0.0.3 area 0

 network 192.168.10.0 0.0.0.255 area 0

配置GRE OVER IPSEC

crypto isakmp enable            //开启ISAKMP

crypto isakmp policy 10     //设置ISAKMP策略

 encr 3des           //使用3DES加密

 hash md5           //用MD5作为摘要算法

 authentication pre-share   //认证方式以预共享密钥

 group 2            //定义DH算法为组2

crypto isakmp identity address //使用用IP地址作为身份标识

crypto isakmp key 0 cisco address 202.202.202.2 //配置预共享密钥和对方IP 0表示不加密显示,默认值 6表示加密显示

crypto ipsec transform-set TS esp-3des esp-sha-hmac//配置传输集参数,用来协商IPSEC SA的策略 (这里使用默认的传输模式,以节省开销)

access-list 101 permit ip host  200.200.200.1 host 202.202.202.2 //定义感兴趣流量 (这里为什么是配置的是公网的IP,是因为去往目标私网的数据经过tunnel口,加上了GRE的头部,目标IP为202.202.202.2,源IP为200.200.200.1)

crypto map RT1 10 ipsec-isakmp //配置加密图(把IPSEC所需参数全部绑定到MAP)

set peer 202.202.202.2    //设置对等体(与对方协商IPSEC)

set transform-set TS     //调用传输集

match address 101       //匹配感兴趣流量(匹配的流量就做IPSEC,基于策略的IPSEC,另一种是基于路由的IPSEC)

int s1/0

crypto map RT1   //在接口上应用加密图

关于为什么要使用传输模式:

由于GRE已经封装了原始数据包,就不需要IPSec再去封装GRE添上的另外的IP包头了,这样可以节省20bytes的包头
 
 
 
RT2上的配置:

interface Serial1/0

 ip address 200.200.200.2 255.255.255.252

 no shutdown

interface Serial1/1

 ip address 202.202.202.1 255.255.255.252

 no shutdown

配置GRE

RT3:

interface Serial1/0

 ip address 202.202.202.2 255.255.255.252

 no shutdown

interface Loopback0

 ip address 192.168.0.3 255.255.255.255

 no shutdown

interface Ethernet0/0

 ip address 192.168.20.1 255.255.255.0

 no shutdown

 int tunnel 0                  

 ip address 192.168.1.3 255.255.255.0

 no shutdown

 tunnel mode gre ip 

 tunnel source 202.202.202.2

 tunnel destination 200.200.200.1

 ip route 0.0.0.0 0.0.0.0 s1/0

router ospf 1

 router-id 192.168.0.3

 passive-interface Serial1/0

 network 192.168.0.3 0.0.0.0 area 0

 network 192.168.1.0 0.0.0.3 area 0

 network 192.168.20.0 0.0.0.255 area 0

配置GRE OVER IPSEC

crypto isakmp enable

crypto isakmp policy 10

encryption 3des

hash md5

authentication pre-share

group 2
crypto isakmp key 0 cisco address 200.200.200.1

crypto ipsec transform-set TS esp-3des esp-sha-hmac

access-list 101 permit ip host 202.202.202.2 host 200.200.200.1

crypto map RT3 10 ipsec-isakmp

set peer 200.200.200.1

set transform-set TS

match address 101

int s1/0

crypto map RT3
 
 
测试私网的连通性
 

 
 
从这个包中我们可以看出,GRE和数据部分都被ESP加密了,这就是GRE OVER IPSEC。从两种不同的报文可以看出,IPSec over GRE,外层的协议还是GRE,仅仅是携带经过IPSec加密过的报文,而GRE over IPSec,是将整个已经封装过的GRE数据包进行加密

下面配置IPSEC OVER GRE

RT1:

crypto isakmp policy 10

 encr 3des

 hash md5

 authentication pre-share

 group 2

crypto isakmp key cisco address 192.168.0.3 //指定对端为LOOPBCAK地址

crypto ipsec transform-set TS esp-3des esp-sha-hmac

 mode transport

crypto map RT1 local-address Loopback0 //指定从LOOPBACK0发送IKE报文

crypto map RT1 10 ipsec-isakmp

 set peer 192.168.0.3

 set transform-set TS

 match address 101

access-list 101 permit ip 192.168.10.0 0.0.0.255 192.168.20.0 0.0.0.255

interface Tunnel0

 ip address 192.168.1.1 255.255.255.0
 tunnel source Serial1/0

 tunnel destination 202.202.202.2
 crypto map RT1

RT3:

crypto isakmp policy 10

 encr 3des

 hash md5

 authentication pre-share

 group 2

crypto isakmp key cisco address 192.168.0.1 //指定对端为LOOPBCAK地址

crypto ipsec transform-set TS esp-3des esp-sha-hmac

 mode transport

crypto map RT3 local-address Loopback0/指定从LOOPBACK0发送IKE报文

crypto map RT3 10 ipsec-isakmp

 set peer 192.168.0.1

 set transform-set TS

 match address 101

interface Tunnel0

 ip address 192.168.1.3 255.255.255.0
 tunnel source Serial1/0

 tunnel destination 200.200.200.1

 crypto map RT3

access-list 101 permit ip 192.168.20.0 0.0.0.255 192.168.10.0 0.0.0.255
 
现在我们可以看到数据部分被ESP加密,之后再加上了一个GRE的头部!这个叫IPSEC OVER GRE

 

感谢红盟过客为我指处的几处错误!已更正!