由于IPSec不支持对多播和广播数据包的加密,这样的话,使用IPSec的隧道中,动态路由协议等依靠多播和广播的协议就不能进行正常通告,所以,这时候要配合GRE隧道,GRE隧道会将多播和广播数据包封装到单播包中,再经过IPSec加密。
此外由于GRE建立的是简单的,不进行加密的×××隧道,他通过在物理链路中使用ip地址和路由穿越普通网络。所以很常见的方法就是使用IPSec对GRE进行加密,提供数据安全保证
试验拓扑:
R2配置:
hostname R2
!
crypto isakmp policy 1
authentication pre-share //这里的认证方式使用的是预共享密钥
crypto isakmp key fuck address 192.168.34.4 //配置预共享密钥
!
crypto ipsec transform-set trans esp-des esp-sha-hmac
mode transport //配置为传输模式
!
crypto map mm 10 ipsec-isakmp
set peer 192.168.34.4
set transform-set trans
match address toR4
!
interface Tunnel0
ip address 192.168.24.2 255.255.255.0
tunnel source Ethernet1/1
tunnel destination 192.168.34.4
!
interface Ethernet1/0
ip address 192.168.1.254 255.255.255.0
!
interface Ethernet1/1
ip address 192.168.23.2 255.255.255.0
crypto map mm
!
ip route 0.0.0.0 0.0.0.0 192.168.23.3
ip route 192.168.2.0 255.255.255.0 Tunnel0
!
ip access-list extended toR4
permit gre host 192.168.23.2 host 192.168.34.4
!
R4配置:
hostname R4
!
crypto isakmp policy 1
authentication pre-share
crypto isakmp key fuck address 192.168.23.2
!
crypto ipsec transform-set trans esp-des esp-sha-hmac
!
crypto map mm 10 ipsec-isakmp
set peer 192.168.23.2
set transform-set trans
match address toR2
!
interface Tunnel0
ip address 192.168.24.4 255.255.255.0
tunnel source Ethernet1/2
tunnel destination 192.168.23.2
!
interface Ethernet1/2
ip address 192.168.34.4 255.255.255.0
crypto map mm
!
interface Ethernet1/3
ip address 192.168.2.254 255.255.255.0
!
ip route 0.0.0.0 0.0.0.0 192.168.34.3
ip route 192.168.1.0 255.255.255.0 Tunnel0 //注意,这里推荐使用静态路由,强制流量走隧道,而不是通过动态路由去学习,这样可以增加隧道流量的安全性
!
ip access-list extended toR2
permit gre host 192.168.34.4 host 192.168.23.2
!
这里IPsec配置为传输模式,由于GRE已经封装了原始数据包,就不需要IPSec再去封装GRE添上的另外的IP包头了,这样可以节省20bytes的包头
由于GRE隧道一直是通的,可以使用下面命令查看isakmp和IPSec安全联结有没有建立成功:
Show crypto isakmp sa
Show crypto ipsec sa
最后进行抓包验证
GRE over IPSec
IPSec over GRE
从两种不同的报文可以看出,IPSec over GRE,外层的协议还是GRE,仅仅是携带经过IPSec加密过的报文,而GRE over IPSec,是将整个已经封装过的GRE数据包进行加密
下面介绍一种使用IPSec保护GRE隧道的新方法:动态加密映射(dynamic crypto maps)
试验拓扑:
R2配置:
hostname R2
!
crypto isakmp policy 1
hash md5
authentication pre-share
lifetime 600
crypto isakmp key 6 fuck address 192.168.34.4
!
crypto ipsec transform-set trans esp-des esp-md5-hmac
mode transport
!
crypto ipsec pro
file mm set transform-set trans
!
interface Tunnel0
ip address 192.168.24.2 255.255.255.0
tunnel source Ethernet1/1
tunnel destination 192.168.34.4
tunnel protection ipsec pro
file mm !
interface Ethernet1/0
ip address 192.168.1.254 255.255.255.0
!
interface Ethernet1/1
ip address 192.168.23.2 255.255.255.0
!
ip route 0.0.0.0 0.0.0.0 192.168.23.3
ip route 192.168.2.0 255.255.255.0 Tunnel0
!
R4配置:
hostname R4
!
crypto isakmp policy 1
hash md5
authentication pre-share
lifetime 600
crypto isakmp key 6 fuck address 192.168.23.2
!
crypto ipsec transform-set trans esp-des esp-md5-hmac
mode transport
!
crypto ipsec pro
file mm set transform-set trans
!
interface Tunnel0
ip address 192.168.24.4 255.255.255.0
tunnel source Ethernet1/2
tunnel destination 192.168.23.2
tunnel protection ipsec pro
file mm !
interface Ethernet1/2
ip address 192.168.34.4 255.255.255.0
!
interface Ethernet1/3
ip address 192.168.2.254 255.255.255.0
!
ip route 0.0.0.0 0.0.0.0 192.168.34.3
ip route 192.168.1.0 255.255.255.0 Tunnel0
!
这两种配置的不同之处在于
- 方法一可以说是一种策略模式的×××,只有符合感兴趣流,才进行加密,而方法二可以说是路由模式×××,只要我们通过路由,将流量引入隧道,这些流量都会进行加密
- 方法一需要在GRE隧道经过的物理接口上配置加密映射(crypto map),而方法二就不需要加密映射了,方法二的映射是通过自己学习的,这样可以减少命令行的配置条目
- 方法一只有在有流量需要保护才会建立SA,而方法二即使没有流量也会建立SA
- 方法一可以在隧道接口上配置GRE存活机制(keepalive),而方法二不支持GRE存活机制