2017年3月16日星期四

阿里云部署strongswan与flexGW (实现linux与cisco asa 5520对接)

0x00 使用flexGW与对端CISCO asa 5520建立IKEv2 ipsec vpn

首先要介绍一下FlexGW,它是阿里开源的一个项目,FlexGW项目地址
它包含了两个开源组件,openvpn、strongswan
但是这里,只需要用到strongswan即可,strongswan的官网首页有许多
IKE相关的RFC编号,可以多看看

环境:
         OpenVPN 2.3.14 x86_64-redhat-linux-gnu
         strongSwan U5.4.0/K2.6.32-573.22.1.el6.x86_64
         CentOS release 6.5 (Final)

0x02 根据官方文档配置

    搭建VPN网关 是阿里官方flexGW web图形配置界面介绍,加上cisco ASA的配置。
    注意配置两端的参数要一致。
     
0x03 我的配置

    首先定义允许经过VPN的流量
    access-list ALIVPN extended permit ip 172.16.0.0 255.255.0.0 10.8.0.0 255.255.0.0
    
    重要提示:在这里可能会出现下面的报错。
    原理:strongswan会把允许的流量列表发过来,必须要与ALIVPN列表精确匹配,
               否则就不能正常建立ipsec sa。
  以下是之前的写法:
               access-list IT-2-ALIVPN extended permit ip 172.16.11.0 255.255.255.0 10.8.0.0 255.255.0.0
  日志错误
        Negotiation aborted due to ERROR: Failed to find a matching policy
  调试错误
    IKEv2-PROTO-1: (64): Failed to find a matching policy
  原因
访问控制列表与对端的流量筛选器不一致


  crypto ikev2 enable wan
  crypto ikev2 policy 10
  encryption aes-256 3des
  integrity sha256 md5
  group 5 2 1
  prf sha256 md5
  lifetime seconds 86400

  tunnel-group HardWay type ipsec-l2l        # 这个一直提示错误的信息
  tunnel-group HardWay ipsec-attributes
  ikev2 remote-authentication pre-shared-key cisco123
  ikev2 local-authentication pre-shared-key cisco123
  
 调试出下面错误
  IKEv2-PLAT-1: Failed to set P1 auth to build policy
  IKEv2-PLAT-1: unable to build ikev2 policy
  IKEv2-PROTO-1: (38): Failed to locate an item in the database
 
 更换了tunnel-group ID后,正常连接隧道
  tunnel-group 99.99.99.99 type ipsec-l2l    # 把HardWay改成99.99.99.99
  tunnel-group 120.77.32.39 ipsec-attributes
  ikev2 remote-authentication pre-shared-key cisco123
  ikev2 local-authentication pre-shared-key cisco123
 
  crypto ipsec ikev2 ipsec-proposal itplus
  protocol esp encryption 3des 
  protocol esp integrity md5
 
 crypto map cry-map 50 match address ALIVPN
 crypto map cry-map 50 set peer 99.99.99.99
 crypto map cry-map 50 set ikev2 ipsec-proposal itplus

 第二次报错
  IKEv2-PLAT-1: IKEv2 protocol not allowed by policy set for vpn-tunnel-protocol
  IKEv2-PLAT-1: Connection is not authorized based on configured attributes
  IKEv2-PROTO-1: (39): Failed to register new SA with platform

 第二次报错的解决方法
 
  group-policy ALI_VPN internal
  group-policy ALI_VPN attributes
  vpn-idle-timeout 30
  vpn-tunnel-protocol ikev2
  
  tunnel-group 99.99.99.99 general-attributes
  default-group-policy ALI_VPN

0x03 两个SA建立后,ping不同?
        

ping不通的原因:
     ESP 数据包必须经过NAT,而经过NAT后源地址被转换,校验失败,数据包丢弃。
     出个问题,ESP数据包可以不走NAT吗?
解决方法:
      在asa做一个二次NAT,让源地址与目标地址都不转换的经过NAT。
 object network XYJCOM
 subnet 172.16.0.0 255.255.0.0
 
 object network ALICLD
 subnet 10.8.0.0 255.255.0.0
 
 nat (lan,wan) source static XYJCOM XYJCOM destination static ALICLD ALICLD no-proxy-arp route-lookup

0x04 排错思路

排除思路:
一种是开debug
debug crypto ikev2 protocol
debug crypto ikev2 platform

另外一种是查看日志

show logging | in x.x.x.x   (过滤对端IP地址)






没有评论:

发表评论