网络拓扑如下

 

ipsec

 

 

 1、公司A端路由器配置

#
//定义需要保护的 安全数据流
acl number 3000
 rule 10 permit ip source 12.12.12.1 0 destination 23.23.23.3 0 
#
// 定义 IKE 对等体
ike peer to_rtb
  // 使用预设口令身份验证
 pre-shared-key 123
  // 对等体的 IP 地址
 remote-address 23.23.23.3
#
// 定义 IPSec 提议
ipsec proposal to_rtb       (注:使用默认值:隧道模式、MD5认证、DES加密)
#
// 定义 IPSec 策略,协商方式为 isakmp ,即使用 IKE 协商
ipsec policy to_rtb 1 isakmp
  // 定义需要加密传送的 ACL
 security acl 3000
  // 选择使用的 IKE 对等体
 ike-peer to_rtb
  // 选择安全策略
 proposal to_rtb
#
interface Ethernet0/0
 port link-mode route
 description WAN
 ip address 12.12.12.1 255.255.255.0
 // 将安全策略绑定在端口下
 ipsec policy to_rtb
#
interface Ethernet0/1
 port link-mode route
 description LAN
 ip address 192.168.1.1 255.255.255.0
#
// 定义 GRE 隧道
interface Tunnel0
 ip address 10.0.0.1 255.255.255.252
 // 指定隧道的源
 source 12.12.12.1
  // 指定隧道的目的
 destination 23.23.23.3
#
 // 定义默认路由
 ip route-static 0.0.0.0 0.0.0.0 12.12.12.2
 //定义静态路由,可以使用动态路由代替
 ip route-static 192.168.2.0 255.255.255.0 Tunnel0
 
 
2、公司B端路由器配置
 
 
#
//定义需要保护的 安全数据流
acl number 3000
 rule 10 permit ip source 23.23.23.3 0 destination 12.12.12.1 0
#
// 定义 IKE 对等体
ike peer to_rta
  // 使用预设口令身份验证
 pre-shared-key 123
  // 对等体的 IP 地址
 remote-address 12.12.12.1
#
// 定义 IPSec 提议
ipsec proposal to_rta       (注:使用默认值:隧道模式、MD5认证、DES加密)
#
// 定义 IPSec 策略,协商方式为 isakmp ,即使用 IKE 协商
ipsec policy to_rta 1 isakmp
  // 定义需要加密传送的 ACL
 security acl 3000
  // 选择使用的 IKE 对等体
 ike-peer to_rta
  // 选择安全策略
 proposal to_rta
#
interface Ethernet0/0
 port link-mode route
 description WAN
 ip address 23.23.23.1 255.255.255.0
 // 将安全策略绑定在端口下
 ipsec policy to_rta
#
interface Ethernet0/1
 port link-mode route
 description LAN
 ip address 192.168.2.1 255.255.255.0
#
// 定义 GRE 隧道
interface Tunnel0
 ip address 10.0.0.2 255.255.255.252
 // 指定隧道的源
 source 12.12.12.1
  // 指定隧道的目的
 destination 23.23.23.3
#
 // 定义默认路由
 ip route-static 0.0.0.0 0.0.0.0 23.23.23.2
 // 定义静态路由,可以使用动态路由代替
 ip route-static 192.168.1.0 255.255.255.0 Tunnel0
 
 
配置完成后先在两边的任意一台路由器上ping一下对端,假设在公司A上PING对端,使用
ping -a 192.168.1.1 192.168.2.1
然后通过display ike sa和display ipsec sa查看ike和ipsec的sa建立情况。
 
 

 配置关键点

1) 安全数据流要匹配IPSec接口;
2) 注意GRE隧道的源和目的,要和IPSec接口吻合;
3) 将子网流量引入GRE隧道。