赞
踩
一、环境介绍
使用libreswan实现Azure与IDC和Office内网互通
环境:【① 源和目的都为虚拟机,具体安装配置于Azures上虚拟机一致;② 其他品牌VPN网关设备】
Azure虚拟机:
内网网段:10.1.12.0/24
公网IP:52.130.186.xx
内网IP:10.1.12.4
系统版本:Centos7
IDC:
内网网段:10.161.30.0/24
公网IP:122.144.208.xx
网络设备:ASA防火墙
Office:
内网网段:192.168.40.0/24
公网IP:60.168.145.xx
网络设备:ASA防火墙
架构图:
二、系统配置
2.1 开启路由转发和关闭源路由验证
- vim /etc/sysctl.conf
-
- net.ipv4.ip_forward = 1
- net.ipv4.conf.all.rp_filter = 0
- net.ipv4.conf.default.rp_filter = 0
- net.ipv4.conf.eth0.rp_filter = 0
- net.ipv4.conf.all.send_redirects = 0
- net.ipv4.conf.default.send_redirects = 0
- net.ipv4.conf.all.log_martians = 0
- net.ipv4.conf.default.log_martians = 0
- net.ipv4.conf.default.accept_source_route = 0
- net.ipv4.conf.all.accept_redirects = 0
- net.ipv4.conf.default.accept_redirects = 0
- net.ipv4.icmp_ignore_bogus_error_responses = 1
2.2 重新加载内核参数
sysctl -p
2.3 关闭selinux和防火墙
- setenforce 0 #临时关闭selinux
- sed -ir '/^SELINUX=/s/=.+/=disabled/' /etc/selinux/config #永久关闭selinux
-
- systemctl stop firewalld
- systemctl disable firewalld
2.4 配置安全组策略
对目的IP开放所有端口或只开放UDP500、UDP4500端口
2.5 开启IP转发
虚拟机-网络-网络接口-IP配置
2.6 创建路由表、关联子网
① 所有服务-网络-路由表-创建-路由-添加
添加office、idc网段指向Azure的路由
②关联子网
所有服务-网络-路由表-子网-关联
三、软件安装
libreswan安装
yum install -y libreswan
查看libreswan版本
yum info libreswan
四、新建ipsec连接
4.1 创建azure-to-idc连接配置:
- vim /etc/ipsec.d/azure-to-idc.conf
-
-
- conn azure-to-idc
- ### phase 1 ###
-
- # 指定认证类型预共享秘钥
- authby=secret
- # 指定ike算法为AES-256-SHA,非对称算法为dh2(根据网络设备和libreswan支持的算法来定)
- ike=AES-256-SHA;dh2
- # 指定ike
- keyexchange=ike
-
- ### phase 2 ###
- phase2=esp
- phase2alg=AES-256-SHA
- # 指定是否压缩
- compress=no
- # 指定是否加密
- pfs=yes
- # 指定连接添加类型。start 为开机自启,add为添加 不主动连接
- auto=start
- # 指定模式类型为隧道模式|传输模式
- type=tunnel
-
- left=10.1.12.4
- leftsubnet=10.1.12.0/24
- leftid=52.130.186.xx
- leftnexthop=%defaultroute
-
- right=122.144.208.xx
- rightsubnet=10.161.30.0/24
- rightid=122.144.208.xx
4.2 新建azure-to-idc共享密钥配置:
- vim /etc/ipsec.d/azure-to-idc.secrets
-
-
- 52.130.186.xx 122.144.208.xx: PSK "K3!R5kj038&#e72uN1e@"
4.3 新建azure-to-office连接配置:
- vim /etc/ipsec.d/azure-to-office.conf
-
-
- conn azure-to-office
- ### phase 1 ###
-
- # 指定认证类型预共享秘钥
- authby=secret
- # 指定ike算法为AES-256-SHA,非对称算法为dh2 (根据网络设备和libreswan支持的算法来定)
- ike=AES-256-SHA;dh2
- # 指定ike
- keyexchange=ike
-
- ### phase 2 ###
- phase2=esp
- phase2alg=AES-256-SHA
- # 指定是否压缩
- compress=no
- # 指定是否加密
- pfs=yes
- # 指定连接添加类型。start 为开机自启,add为添加 不主动连接
- auto=start
- # 指定模式类型为隧道模式|传输模式
- type=tunnel
-
- left=10.1.12.4
- leftsubnet=10.1.12.0/24
- leftid=52.130.186.xx
- leftnexthop=%defaultroute
-
- right=60.168.145.xx
- rightsubnet=192.168.40.0/24
- rightid=60.168.145.xx
4.4 新建azure-to-office共享密钥配置:
- vim /etc/ipsec.d/azure-to-office.secrets
-
- 52.130.186.xx 60.168.145.xx: PSK "K3!R5kj038&#e72uN1e@"
4.5 重启ipsec服务
systemctl restart ipsec
五、配置ASA(因idc和office配置一致,这里只展现一台配置)
1.1 idc配置如下
六、测试
6.1 测试ASA设备UDP端口,如端口不通,请开放UDP 4500、500端口
nmap -sU ASA公网IP -p 4500,500 -Pn
6.2 查看隧道建立情况
- ipsec auto --status
-
- 000 using kernel interface: netkey
- 000 interface lo/lo ::1@500
- 000 interface lo/lo 127.0.0.1@4500
- 000 interface lo/lo 127.0.0.1@500
- 000 interface eth0/eth0 10.1.12.4@4500
- 000 interface eth0/eth0 10.1.12.4@500
- 000
- 000
- 000 fips mode=disabled;
- 000 SElinux=disabled
- 000 seccomp=disabled
- 000
- 000 config setup options:
- 000
- 000 configdir=/etc, configfile=/etc/ipsec.conf, secrets=/etc/ipsec.secrets, ipsecdir=/etc/ipsec.d
- 000 nssdir=/etc/ipsec.d, dumpdir=/run/pluto, statsbin=unset
- 000 dnssec-rootkey-file=/var/lib/unbound/root.key, dnssec-trusted=<unset>
- 000 sbindir=/usr/sbin, libexecdir=/usr/libexec/ipsec
- 000 pluto_version=3.25, pluto_vendorid=OE-Libreswan-3.25
- 000 nhelpers=-1, uniqueids=yes, dnssec-enable=yes, perpeerlog=no, logappend=yes, logip=yes, shuntlifetime=900s, xfrmlifetime=300s
- 000 ddos-cookies-threshold=50000, ddos-max-halfopen=25000, ddos-mode=auto
- 000 ikeport=500, ikebuf=0, msg_errqueue=yes, strictcrlpolicy=no, crlcheckinterval=0, listen=<any>, nflog-all=0
- 000 ocsp-enable=no, ocsp-strict=no, ocsp-timeout=2, ocsp-uri=<unset>
- 000 ocsp-trust-name=<unset>
- 000 ocsp-cache-size=1000, ocsp-cache-min-age=3600, ocsp-cache-max-age=86400, ocsp-method=get
- 000 secctx-attr-type=32001
- 000 debug:
- 000
- 000 nat-traversal=yes, keep-alive=20, nat-ikeport=4500
- 000 virtual-private (%priv):
- 000 - allowed subnets: 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, 25.0.0.0/8, 100.64.0.0/10, fd00::/8, fe80::/10
- 000
- 000 ESP algorithms supported:
- 000
- 000 algorithm ESP encrypt: id=3, name=ESP_3DES, ivlen=8, keysizemin=192, keysizemax=192
- 000 algorithm ESP encrypt: id=6, name=ESP_CAST, ivlen=8, keysizemin=128, keysizemax=128
- 000 algorithm ESP encrypt: id=11, name=ESP_NULL, ivlen=0, keysizemin=0, keysizemax=0
- 000 algorithm ESP encrypt: id=12, name=ESP_AES, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=13, name=ESP_AES_CTR, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=14, name=ESP_AES_CCM_A, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=15, name=ESP_AES_CCM_B, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=16, name=ESP_AES_CCM_C, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=18, name=ESP_AES_GCM_A, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=19, name=ESP_AES_GCM_B, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=20, name=ESP_AES_GCM_C, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=22, name=ESP_CAMELLIA, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=23, name=ESP_NULL_AUTH_AES_GMAC, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=252, name=ESP_SERPENT, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm ESP encrypt: id=253, name=ESP_TWOFISH, ivlen=8, keysizemin=128, keysizemax=256
- 000 algorithm AH/ESP auth: id=1, name=AUTH_ALGORITHM_HMAC_MD5, keysizemin=128, keysizemax=128
- 000 algorithm AH/ESP auth: id=2, name=AUTH_ALGORITHM_HMAC_SHA1, keysizemin=160, keysizemax=160
- 000 algorithm AH/ESP auth: id=5, name=AUTH_ALGORITHM_HMAC_SHA2_256, keysizemin=256, keysizemax=256
- 000 algorithm AH/ESP auth: id=6, name=AUTH_ALGORITHM_HMAC_SHA2_384, keysizemin=384, keysizemax=384
- 000 algorithm AH/ESP auth: id=7, name=AUTH_ALGORITHM_HMAC_SHA2_512, keysizemin=512, keysizemax=512
- 000 algorithm AH/ESP auth: id=8, name=AUTH_ALGORITHM_HMAC_RIPEMD, keysizemin=160, keysizemax=160
- 000 algorithm AH/ESP auth: id=9, name=AUTH_ALGORITHM_AES_XCBC, keysizemin=128, keysizemax=128
- 000 algorithm AH/ESP auth: id=250, name=AUTH_ALGORITHM_AES_CMAC_96, keysizemin=128, keysizemax=128
- 000 algorithm AH/ESP auth: id=251, name=AUTH_ALGORITHM_NULL_KAME, keysizemin=0, keysizemax=0
- 000
- 000 IKE algorithms supported:
- 000
- 000 algorithm IKE encrypt: v1id=5, v1name=OAKLEY_3DES_CBC, v2id=3, v2name=3DES, blocksize=8, keydeflen=192
- 000 algorithm IKE encrypt: v1id=8, v1name=OAKLEY_CAMELLIA_CBC, v2id=23, v2name=CAMELLIA_CBC, blocksize=16, keydeflen=128
- 000 algorithm IKE encrypt: v1id=-1, v1name=n/a, v2id=20, v2name=AES_GCM_C, blocksize=16, keydeflen=128
- 000 algorithm IKE encrypt: v1id=-1, v1name=n/a, v2id=19, v2name=AES_GCM_B, blocksize=16, keydeflen=128
- 000 algorithm IKE encrypt: v1id=-1, v1name=n/a, v2id=18, v2name=AES_GCM_A, blocksize=16, keydeflen=128
- 000 algorithm IKE encrypt: v1id=13, v1name=OAKLEY_AES_CTR, v2id=13, v2name=AES_CTR, blocksize=16, keydeflen=128
- 000 algorithm IKE encrypt: v1id=7, v1name=OAKLEY_AES_CBC, v2id=12, v2name=AES_CBC, blocksize=16, keydeflen=128
- 000 algorithm IKE encrypt: v1id=65004, v1name=OAKLEY_SERPENT_CBC, v2id=65004, v2name=SERPENT_CBC, blocksize=16, keydeflen=128
- 000 algorithm IKE encrypt: v1id=65005, v1name=OAKLEY_TWOFISH_CBC, v2id=65005, v2name=TWOFISH_CBC, blocksize=16, keydeflen=128
- 000 algorithm IKE encrypt: v1id=65289, v1name=OAKLEY_TWOFISH_CBC_SSH, v2id=65289, v2name=TWOFISH_CBC_SSH, blocksize=16, keydeflen=128
- 000 algorithm IKE PRF: name=HMAC_MD5, hashlen=16
- 000 algorithm IKE PRF: name=HMAC_SHA1, hashlen=20
- 000 algorithm IKE PRF: name=HMAC_SHA2_256, hashlen=32
- 000 algorithm IKE PRF: name=HMAC_SHA2_384, hashlen=48
- 000 algorithm IKE PRF: name=HMAC_SHA2_512, hashlen=64
- 000 algorithm IKE PRF: name=AES_XCBC, hashlen=16
- 000 algorithm IKE DH Key Exchange: name=MODP1024, bits=1024
- 000 algorithm IKE DH Key Exchange: name=MODP1536, bits=1536
- 000 algorithm IKE DH Key Exchange: name=MODP2048, bits=2048
- 000 algorithm IKE DH Key Exchange: name=MODP3072, bits=3072
- 000 algorithm IKE DH Key Exchange: name=MODP4096, bits=4096
- 000 algorithm IKE DH Key Exchange: name=MODP6144, bits=6144
- 000 algorithm IKE DH Key Exchange: name=MODP8192, bits=8192
- 000 algorithm IKE DH Key Exchange: name=DH19, bits=512
- 000 algorithm IKE DH Key Exchange: name=DH20, bits=768
- 000 algorithm IKE DH Key Exchange: name=DH21, bits=1056
- 000 algorithm IKE DH Key Exchange: name=DH22, bits=1024
- 000 algorithm IKE DH Key Exchange: name=DH23, bits=2048
- 000 algorithm IKE DH Key Exchange: name=DH24, bits=2048
- 000
- 000 stats db_ops: {curr_cnt, total_cnt, maxsz} :context={0,351381,64} trans={0,351381,6936} attrs={0,351381,4624}
- 000
- 000 Connection list:
- 000
- 000 "azure-to-hfoffice": 10.1.12.0/24===10.1.12.4<10.1.12.4>[52.130.186.xx]---10.1.12.1...60.168.145.xx<60.168.145.xx>===192.168.40.0/24; erouted; eroute owner: #630098
- 000 "azure-to-hfoffice": oriented; my_ip=unset; their_ip=unset; my_updown=ipsec _updown;
- 000 "azure-to-hfoffice": xauth us:none, xauth them:none, my_username=[any]; their_username=[any]
- 000 "azure-to-hfoffice": our auth:secret, their auth:secret
- 000 "azure-to-hfoffice": modecfg info: us:none, them:none, modecfg policy:push, dns:unset, domains:unset, banner:unset, cat:unset;
- 000 "azure-to-hfoffice": labeled_ipsec:no;
- 000 "azure-to-hfoffice": policy_label:unset;
- 000 "azure-to-hfoffice": ike_life: 3600s; ipsec_life: 28800s; replay_window: 32; rekey_margin: 540s; rekey_fuzz: 100%; keyingtries: 0;
- 000 "azure-to-hfoffice": retransmit-interval: 500ms; retransmit-timeout: 60s;
- 000 "azure-to-hfoffice": initial-contact:no; cisco-unity:no; fake-strongswan:no; send-vendorid:no; send-no-esp-tfc:no;
- 000 "azure-to-hfoffice": policy: PSK+ENCRYPT+TUNNEL+PFS+UP+IKEV1_ALLOW+IKEV2_ALLOW+SAREF_TRACK+IKE_FRAG_ALLOW+ESN_NO;
- 000 "azure-to-hfoffice": conn_prio: 24,24; interface: eth0; metric: 0; mtu: unset; sa_prio:auto; sa_tfc:none;
- 000 "azure-to-hfoffice": nflog-group: unset; mark: unset; vti-iface:unset; vti-routing:no; vti-shared:no; nic-offload:auto;
- 000 "azure-to-hfoffice": our idtype: ID_IPV4_ADDR; our id=52.130.186.xx; their idtype: ID_IPV4_ADDR; their id=60.168.145.xx
- 000 "azure-to-hfoffice": dpd: action:hold; delay:0; timeout:0; nat-t: encaps:auto; nat_keepalive:yes; ikev1_natt:both
- 000 "azure-to-hfoffice": newest ISAKMP SA: #630097; newest IPsec SA: #630098;
- 000 "azure-to-hfoffice": IKE algorithms: AES_CBC_256-HMAC_SHA1-MODP1024
- 000 "azure-to-hfoffice": IKE algorithm newest: AES_CBC_256-HMAC_SHA1-MODP1024
- 000 "azure-to-hfoffice": ESP algorithms: AES_CBC_256-HMAC_SHA1_96
- 000 "azure-to-hfoffice": ESP algorithm newest: AES_CBC_256-HMAC_SHA1_96; pfsgroup=<Phase1>
- 000 "azure-to-idc": 10.1.12.0/24===10.1.12.4<10.1.12.4>[52.130.186.66]---10.1.12.1...122.144.208.xx<122.144.208.xx>===10.161.30.0/24; erouted; eroute owner: #630074
- 000 "azure-to-idc": oriented; my_ip=unset; their_ip=unset; my_updown=ipsec _updown;
- 000 "azure-to-idc": xauth us:none, xauth them:none, my_username=[any]; their_username=[any]
- 000 "azure-to-idc": our auth:secret, their auth:secret
- 000 "azure-to-idc": modecfg info: us:none, them:none, modecfg policy:push, dns:unset, domains:unset, banner:unset, cat:unset;
- 000 "azure-to-idc": labeled_ipsec:no;
- 000 "azure-to-idc": policy_label:unset;
- 000 "azure-to-idc": ike_life: 3600s; ipsec_life: 28800s; replay_window: 32; rekey_margin: 540s; rekey_fuzz: 100%; keyingtries: 0;
- 000 "azure-to-idc": retransmit-interval: 500ms; retransmit-timeout: 60s;
- 000 "azure-to-idc": initial-contact:no; cisco-unity:no; fake-strongswan:no; send-vendorid:no; send-no-esp-tfc:no;
- 000 "azure-to-idc": policy: PSK+ENCRYPT+TUNNEL+PFS+IKEV1_ALLOW+IKEV2_ALLOW+SAREF_TRACK+IKE_FRAG_ALLOW+ESN_NO;
- 000 "azure-to-idc": conn_prio: 24,24; interface: eth0; metric: 0; mtu: unset; sa_prio:auto; sa_tfc:none;
- 000 "azure-to-idc": nflog-group: unset; mark: unset; vti-iface:unset; vti-routing:no; vti-shared:no; nic-offload:auto;
- 000 "azure-to-idc": our idtype: ID_IPV4_ADDR; our id=52.130.186.xx; their idtype: ID_IPV4_ADDR; their id=122.144.208.xx
- 000 "azure-to-idc": dpd: action:hold; delay:0; timeout:0; nat-t: encaps:auto; nat_keepalive:yes; ikev1_natt:both
- 000 "azure-to-idc": newest ISAKMP SA: #630099; newest IPsec SA: #630074;
- 000 "azure-to-idc": IKE algorithms: AES_CBC_256-HMAC_SHA1-MODP1024
- 000 "azure-to-idc": IKE algorithm newest: AES_CBC_256-HMAC_SHA1-MODP1024
- 000 "azure-to-idc": ESP algorithms: AES_CBC_256-HMAC_SHA1_96
- 000 "azure-to-idc": ESP algorithm newest: AES_CBC_256-HMAC_SHA1_96; pfsgroup=<Phase1>
- 000
- 000 Total IPsec connections: loaded 2, active 2
- 000
- 000 State Information: DDoS cookies not required, Accepting new IKE connections
- 000 IKE SAs: total(2), half-open(0), open(0), authenticated(2), anonymous(0)
- 000 IPsec SAs: total(2), authenticated(2), anonymous(0)
- 000
- 000 #630097: "azure-to-hfoffice":4500 STATE_MAIN_I4 (ISAKMP SA established); EVENT_SA_REPLACE in 1135s; newest ISAKMP; lastdpd=8s(seq in:0 out:0); idle; import:admin initiate
- 000 #630098: "azure-to-hfoffice":4500 STATE_QUICK_I2 (sent QI2, IPsec SA established); EVENT_SA_REPLACE in 26359s; newest IPSEC; eroute owner; isakmp#630097; idle; import:admin initiate
- 000 #630098: "azure-to-hfoffice" esp.990a220@60.168.145.234 esp.aec62696@10.1.12.4 tun.0@60.168.145.234 tun.0@10.1.12.4 ref=0 refhim=0 Traffic: ESPin=0B ESPout=0B! ESPmax=4194303B
- 000 #630074: "azure-to-idc":4500 STATE_QUICK_R2 (IPsec SA established); EVENT_SA_REPLACE in 15936s; newest IPSEC; eroute owner; isakmp#630073; idle; import:not set
- 000 #630074: "azure-to-idc" esp.b2562ef8@122.144.208.126 esp.72f066af@10.1.12.4 tun.0@122.144.208.126 tun.0@10.1.12.4 ref=0 refhim=0 Traffic: ESPin=727KB ESPout=727KB! ESPmax=4500B
- 000 #630099: "azure-to-idc":4500 STATE_MAIN_R3 (sent MR3, ISAKMP SA established); EVENT_SA_REPLACE in 2168s; newest ISAKMP; lastdpd=-1s(seq in:0 out:0); idle; import:not set
- 000
- 000 Bare Shunt list:
- 000
六、激活隧道
进行ping测试激活隧道
七、排错
1、无法通信可能是因为ASA inside端口错误
2、两端加密方式需配置一致
3、默认IKE v1协议
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。