IPsec不支持OSPF,OSPF hello包是组播
GRE做起来给数据包加了个新的头部变成了单播,ospf互相学习路由,再用IPsec去保护单播的gre
AR2和AR3先配路由:
AR2: ip route-static 20.1.2.0 255.255.255.0 20.1.1.2
AR3:ip route-static 20.1.1.0 255.255.255.0 20.1.2.2
AR2:
创建Tunnle口,相当于逻辑上的一条线
interface Tunnel0/0/0
ip address 172.16.1.1 255.255.255.0
tunnel-protocol gre
source 20.1.1.1
destination 20.1.2.1
AR3:
interface Tunnel0/0/0
ip address 172.16.1.2 255.255.255.0
tunnel-protocol gre
source 20.1.2.1
destination 20.1.1.1
配完查看tunnle口是否起来
配ospf宣告建立邻居
AR2:
ospf 1
area 0.0.0.0
network 172.16.1.0 0.0.0.255
network 192.168.1.0 0.0.0.255
AR3:
ospf 1
area 0.0.0.0
network 172.16.1.0 0.0.0.255
network 192.168.2.0 0.0.0.255
#
用ipsec去保护gre的报文
配置ipsec感兴趣流保护gre的流量是20.1.1.0和20.1.2.0:
AR2:
acl 3000
rule permit gre source 20.1.1.1 0.0.0.0 destination 20.1.2.1 0.0.0.0
rule deny ip source any destination any
这里是gre不是ip是保护gre流量
用ipsec传输模式,不需要加新头部,单纯保护数据
创建安全提议,名字为testipsec
ipsec proposal testipsec
encapsulation-mode transport
封装模式esp,因为有加密需求,用esp而不是ah
transform esp
加密算法
esp encryption-algorithm aes-256
哈希算法
esp authentication-algorithm sha2-256
quit
配置ike
创建ike提议,编号为1
ike proposal 1
使用预共享密钥的方式进行验证
authentication-method pre
协商密钥过程,用dh-group1算法进行加密
dh group1
quit
配置对等体
创建对等体,名字为changsha,使用ike v1和对方做密钥协商,v1是主流版本,v2是最新版本
ike peer changsha v1
使用主模式main建立ipsec
双方都有固定公网ip的时候,使用主模式,如果一方没有固定ip可以使用野蛮模式aggressive
exchange-mode main
调用前面配好的密钥协商方法
ike-proposal 1
预共享密钥,两边一致
pre-shared-key cipher testkey
通过ip地址来互相识别对方,不使用ip地址的话,也可以使用域名
local-id-type ip
ipsec对等体的ip地址,也就是要和这个设备建立ipsec连接
remote-address 20.1.2.1
quit
创建ipsec策略
创建一个ipsec策略,名称是testpolicy 编号是3,后面isakmp意思是密钥会周期性动态更新
ipsec policy testpolicy 3 isakmp
前面定义的ipsec对等体
ike-peer changsha
前面定义好的安全提议
proposal testipsec
前面定义好的感兴趣流
security acl 3000
quit
深圳配好了,长沙的同样配置,acl目标和源换一下,然后红标换一下地址
最后是做出接口调用
int g0/0/1
ipsec policy testpolicy
最后用pc1去ping pc2然后在出端口抓包
可以看到抓到的包都是esp封装的密文的包