GRE over IPsec配置及原理
背景:
ipsec具有可靠性,完整性,机密性,甚至还有抗重放功能,安全性很高,但是,ipsec不支持组播,这就意味着在ipsec隧道中,只能通过写静态路由来引导数据包,如果私网的主机数较少还好,如果主机数网段很多,意味着得一条一条的写静态
GRE具有很牛的隧道技术,传输速度快,并且支持组播技术
但是,GRE不支持加密,就意味着传输的数据别人都能看的见,安全性不高
怎么才能使通信即快,又方便,又安全呢?
GRE 和IPsec的联动解决了这个问题
GRE隧道传输的同时,ipsec又为他保驾护航
配置:
- 先配置GRE的隧道,并且可以通过ospf宣告网段建立邻居,但是,不能宣告公网口地址,否则会造成路由黑洞,详细的解释可以看另一篇博客:GRE配置详解和路由黑洞及检测技术
RT1:
int tunnel 0/0/1
tunn gre
ip add 172.16.13.1 24
sour 12.0.0.1 des
23.0.0.3ospf 1 router-id 1.1.1.1
a 0
net 192.168.10.0 0.0.0.255
net 172.16.13.0 0.0.0.255
RT3:
int tunnel 0/0/1
tunn gre
ip add 172.16.13.2 24
sour 23.0.0.3
des 12.0.0.1
ospf 1 router-id 3.3.3.3
a 0
net 192.168.20.0 0.0.0.255
net 172.16.13.0 0.0.0.255
配置完GRE后,隧道已经建立好了,可以配置IPsec来进行加密
这里ipsec可以选择传输模式,因为GRE会在头部封装公网地址,ipsec隧道模式也会在esp外面封装公网地址,所以可以选择传输模式,节约开销
配置:
RT3:(使用的是ipsec传输模式和ike协商模式)
ike proposal 1
encryption-algorithm aes-cbc-128
authentication-algorithm md5
dh group2
ipsec proposal hefei
encapsulation-mode transport
esp authentication-algorithm sha1
esp encryption-algorithm aes-128
ike peer hefei v1
pre-shared-key cipher 123.com
ike-proposal 1
local-address 23.0.0.3
remote-address 12.0.0.1
acl 3000
rule 5 per gre so 23.0.0.3 0 des 12.0.0.1 0
ipsec policy hefei 1 isakmp
pro hefei
ike-peer hefei
sec acl 3000
RT1:(使用的是ipsec传输模式和ike协商模式)
ike proposal 1
encryption-algorithm aes-cbc-128
authentication-algorithm md5
dh group2
ipsec proposal shanghai
encapsulation-mode transport
esp authentication-algorithm sha1
esp encryption-algorithm aes-128
ike peer shanghai v1
pre-shared-key cipher 123.com
ike-proposal 1
local-address 12.0.0.1
remote-address 23.0.0.3
acl 3000
rule 5 per gre so 12.0.0.1 0 des 23.0.0.3 0
ipsec policy shanghai 1 isakmp
pro shanghai
ike-peer shanghai
sec acl 3000
这里的acl感兴趣流的地址要配置公网地址,因为会先到GRE的隧道中,打上新的ip头部,新的头部使用的是公网地址,ipsec是根据流量触发的,如果使用私网地址无法触发ipsec的机制
在接口未调用ipsec前是可以看到GRE头部,GRE封装的新ip头部,并且里面的私网地址,数据,以及数据包类型都可以看的一清二楚
根据推测,这个应该是ospf的hello报文,但是通过ipsec的封装,除了公网地址,其他什么也看不见
巧妙的解决了刚开始的问题