当前位置:   article > 正文

Azure自建虚拟机与线下IDC和Office ASA防火墙建立ipsec,实现内网互通_查看libreswan版本

查看libreswan版本

一、环境介绍

使用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 开启路由转发和关闭源路由验证

  1. vim /etc/sysctl.conf
  2. net.ipv4.ip_forward = 1
  3. net.ipv4.conf.all.rp_filter = 0
  4. net.ipv4.conf.default.rp_filter = 0
  5. net.ipv4.conf.eth0.rp_filter = 0
  6. net.ipv4.conf.all.send_redirects = 0
  7. net.ipv4.conf.default.send_redirects = 0
  8. net.ipv4.conf.all.log_martians = 0
  9. net.ipv4.conf.default.log_martians = 0
  10. net.ipv4.conf.default.accept_source_route = 0
  11. net.ipv4.conf.all.accept_redirects = 0
  12. net.ipv4.conf.default.accept_redirects = 0
  13. net.ipv4.icmp_ignore_bogus_error_responses = 1

2.2 重新加载内核参数

sysctl -p

 2.3 关闭selinux和防火墙

  1. setenforce 0 #临时关闭selinux
  2. sed -ir '/^SELINUX=/s/=.+/=disabled/' /etc/selinux/config #永久关闭selinux
  3. systemctl stop firewalld
  4. 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连接配置:

  1. vim /etc/ipsec.d/azure-to-idc.conf
  2. conn azure-to-idc
  3. ### phase 1 ###
  4. # 指定认证类型预共享秘钥
  5. authby=secret
  6. # 指定ike算法为AES-256-SHA,非对称算法为dh2(根据网络设备和libreswan支持的算法来定)
  7. ike=AES-256-SHA;dh2
  8. # 指定ike
  9. keyexchange=ike
  10. ### phase 2 ###
  11. phase2=esp
  12. phase2alg=AES-256-SHA
  13. # 指定是否压缩
  14. compress=no
  15. # 指定是否加密
  16. pfs=yes
  17. # 指定连接添加类型。start 为开机自启,add为添加 不主动连接
  18. auto=start
  19. # 指定模式类型为隧道模式|传输模式
  20. type=tunnel
  21. left=10.1.12.4
  22. leftsubnet=10.1.12.0/24
  23. leftid=52.130.186.xx
  24. leftnexthop=%defaultroute
  25. right=122.144.208.xx
  26. rightsubnet=10.161.30.0/24
  27. rightid=122.144.208.xx

4.2 新建azure-to-idc共享密钥配置:

  1. vim /etc/ipsec.d/azure-to-idc.secrets
  2. 52.130.186.xx 122.144.208.xx: PSK "K3!R5kj038&#e72uN1e@"

4.3 新建azure-to-office连接配置:

  1. vim /etc/ipsec.d/azure-to-office.conf
  2. conn azure-to-office
  3. ### phase 1 ###
  4. # 指定认证类型预共享秘钥
  5. authby=secret
  6. # 指定ike算法为AES-256-SHA,非对称算法为dh2 (根据网络设备和libreswan支持的算法来定)
  7. ike=AES-256-SHA;dh2
  8. # 指定ike
  9. keyexchange=ike
  10. ### phase 2 ###
  11. phase2=esp
  12. phase2alg=AES-256-SHA
  13. # 指定是否压缩
  14. compress=no
  15. # 指定是否加密
  16. pfs=yes
  17. # 指定连接添加类型。start 为开机自启,add为添加 不主动连接
  18. auto=start
  19. # 指定模式类型为隧道模式|传输模式
  20. type=tunnel
  21. left=10.1.12.4
  22. leftsubnet=10.1.12.0/24
  23. leftid=52.130.186.xx
  24. leftnexthop=%defaultroute
  25. right=60.168.145.xx
  26. rightsubnet=192.168.40.0/24
  27. rightid=60.168.145.xx

4.4 新建azure-to-office共享密钥配置:

  1. vim /etc/ipsec.d/azure-to-office.secrets
  2. 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 查看隧道建立情况

  1. ipsec auto --status
  2. 000 using kernel interface: netkey
  3. 000 interface lo/lo ::1@500
  4. 000 interface lo/lo 127.0.0.1@4500
  5. 000 interface lo/lo 127.0.0.1@500
  6. 000 interface eth0/eth0 10.1.12.4@4500
  7. 000 interface eth0/eth0 10.1.12.4@500
  8. 000
  9. 000
  10. 000 fips mode=disabled;
  11. 000 SElinux=disabled
  12. 000 seccomp=disabled
  13. 000
  14. 000 config setup options:
  15. 000
  16. 000 configdir=/etc, configfile=/etc/ipsec.conf, secrets=/etc/ipsec.secrets, ipsecdir=/etc/ipsec.d
  17. 000 nssdir=/etc/ipsec.d, dumpdir=/run/pluto, statsbin=unset
  18. 000 dnssec-rootkey-file=/var/lib/unbound/root.key, dnssec-trusted=<unset>
  19. 000 sbindir=/usr/sbin, libexecdir=/usr/libexec/ipsec
  20. 000 pluto_version=3.25, pluto_vendorid=OE-Libreswan-3.25
  21. 000 nhelpers=-1, uniqueids=yes, dnssec-enable=yes, perpeerlog=no, logappend=yes, logip=yes, shuntlifetime=900s, xfrmlifetime=300s
  22. 000 ddos-cookies-threshold=50000, ddos-max-halfopen=25000, ddos-mode=auto
  23. 000 ikeport=500, ikebuf=0, msg_errqueue=yes, strictcrlpolicy=no, crlcheckinterval=0, listen=<any>, nflog-all=0
  24. 000 ocsp-enable=no, ocsp-strict=no, ocsp-timeout=2, ocsp-uri=<unset>
  25. 000 ocsp-trust-name=<unset>
  26. 000 ocsp-cache-size=1000, ocsp-cache-min-age=3600, ocsp-cache-max-age=86400, ocsp-method=get
  27. 000 secctx-attr-type=32001
  28. 000 debug:
  29. 000
  30. 000 nat-traversal=yes, keep-alive=20, nat-ikeport=4500
  31. 000 virtual-private (%priv):
  32. 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
  33. 000
  34. 000 ESP algorithms supported:
  35. 000
  36. 000 algorithm ESP encrypt: id=3, name=ESP_3DES, ivlen=8, keysizemin=192, keysizemax=192
  37. 000 algorithm ESP encrypt: id=6, name=ESP_CAST, ivlen=8, keysizemin=128, keysizemax=128
  38. 000 algorithm ESP encrypt: id=11, name=ESP_NULL, ivlen=0, keysizemin=0, keysizemax=0
  39. 000 algorithm ESP encrypt: id=12, name=ESP_AES, ivlen=8, keysizemin=128, keysizemax=256
  40. 000 algorithm ESP encrypt: id=13, name=ESP_AES_CTR, ivlen=8, keysizemin=128, keysizemax=256
  41. 000 algorithm ESP encrypt: id=14, name=ESP_AES_CCM_A, ivlen=8, keysizemin=128, keysizemax=256
  42. 000 algorithm ESP encrypt: id=15, name=ESP_AES_CCM_B, ivlen=8, keysizemin=128, keysizemax=256
  43. 000 algorithm ESP encrypt: id=16, name=ESP_AES_CCM_C, ivlen=8, keysizemin=128, keysizemax=256
  44. 000 algorithm ESP encrypt: id=18, name=ESP_AES_GCM_A, ivlen=8, keysizemin=128, keysizemax=256
  45. 000 algorithm ESP encrypt: id=19, name=ESP_AES_GCM_B, ivlen=8, keysizemin=128, keysizemax=256
  46. 000 algorithm ESP encrypt: id=20, name=ESP_AES_GCM_C, ivlen=8, keysizemin=128, keysizemax=256
  47. 000 algorithm ESP encrypt: id=22, name=ESP_CAMELLIA, ivlen=8, keysizemin=128, keysizemax=256
  48. 000 algorithm ESP encrypt: id=23, name=ESP_NULL_AUTH_AES_GMAC, ivlen=8, keysizemin=128, keysizemax=256
  49. 000 algorithm ESP encrypt: id=252, name=ESP_SERPENT, ivlen=8, keysizemin=128, keysizemax=256
  50. 000 algorithm ESP encrypt: id=253, name=ESP_TWOFISH, ivlen=8, keysizemin=128, keysizemax=256
  51. 000 algorithm AH/ESP auth: id=1, name=AUTH_ALGORITHM_HMAC_MD5, keysizemin=128, keysizemax=128
  52. 000 algorithm AH/ESP auth: id=2, name=AUTH_ALGORITHM_HMAC_SHA1, keysizemin=160, keysizemax=160
  53. 000 algorithm AH/ESP auth: id=5, name=AUTH_ALGORITHM_HMAC_SHA2_256, keysizemin=256, keysizemax=256
  54. 000 algorithm AH/ESP auth: id=6, name=AUTH_ALGORITHM_HMAC_SHA2_384, keysizemin=384, keysizemax=384
  55. 000 algorithm AH/ESP auth: id=7, name=AUTH_ALGORITHM_HMAC_SHA2_512, keysizemin=512, keysizemax=512
  56. 000 algorithm AH/ESP auth: id=8, name=AUTH_ALGORITHM_HMAC_RIPEMD, keysizemin=160, keysizemax=160
  57. 000 algorithm AH/ESP auth: id=9, name=AUTH_ALGORITHM_AES_XCBC, keysizemin=128, keysizemax=128
  58. 000 algorithm AH/ESP auth: id=250, name=AUTH_ALGORITHM_AES_CMAC_96, keysizemin=128, keysizemax=128
  59. 000 algorithm AH/ESP auth: id=251, name=AUTH_ALGORITHM_NULL_KAME, keysizemin=0, keysizemax=0
  60. 000
  61. 000 IKE algorithms supported:
  62. 000
  63. 000 algorithm IKE encrypt: v1id=5, v1name=OAKLEY_3DES_CBC, v2id=3, v2name=3DES, blocksize=8, keydeflen=192
  64. 000 algorithm IKE encrypt: v1id=8, v1name=OAKLEY_CAMELLIA_CBC, v2id=23, v2name=CAMELLIA_CBC, blocksize=16, keydeflen=128
  65. 000 algorithm IKE encrypt: v1id=-1, v1name=n/a, v2id=20, v2name=AES_GCM_C, blocksize=16, keydeflen=128
  66. 000 algorithm IKE encrypt: v1id=-1, v1name=n/a, v2id=19, v2name=AES_GCM_B, blocksize=16, keydeflen=128
  67. 000 algorithm IKE encrypt: v1id=-1, v1name=n/a, v2id=18, v2name=AES_GCM_A, blocksize=16, keydeflen=128
  68. 000 algorithm IKE encrypt: v1id=13, v1name=OAKLEY_AES_CTR, v2id=13, v2name=AES_CTR, blocksize=16, keydeflen=128
  69. 000 algorithm IKE encrypt: v1id=7, v1name=OAKLEY_AES_CBC, v2id=12, v2name=AES_CBC, blocksize=16, keydeflen=128
  70. 000 algorithm IKE encrypt: v1id=65004, v1name=OAKLEY_SERPENT_CBC, v2id=65004, v2name=SERPENT_CBC, blocksize=16, keydeflen=128
  71. 000 algorithm IKE encrypt: v1id=65005, v1name=OAKLEY_TWOFISH_CBC, v2id=65005, v2name=TWOFISH_CBC, blocksize=16, keydeflen=128
  72. 000 algorithm IKE encrypt: v1id=65289, v1name=OAKLEY_TWOFISH_CBC_SSH, v2id=65289, v2name=TWOFISH_CBC_SSH, blocksize=16, keydeflen=128
  73. 000 algorithm IKE PRF: name=HMAC_MD5, hashlen=16
  74. 000 algorithm IKE PRF: name=HMAC_SHA1, hashlen=20
  75. 000 algorithm IKE PRF: name=HMAC_SHA2_256, hashlen=32
  76. 000 algorithm IKE PRF: name=HMAC_SHA2_384, hashlen=48
  77. 000 algorithm IKE PRF: name=HMAC_SHA2_512, hashlen=64
  78. 000 algorithm IKE PRF: name=AES_XCBC, hashlen=16
  79. 000 algorithm IKE DH Key Exchange: name=MODP1024, bits=1024
  80. 000 algorithm IKE DH Key Exchange: name=MODP1536, bits=1536
  81. 000 algorithm IKE DH Key Exchange: name=MODP2048, bits=2048
  82. 000 algorithm IKE DH Key Exchange: name=MODP3072, bits=3072
  83. 000 algorithm IKE DH Key Exchange: name=MODP4096, bits=4096
  84. 000 algorithm IKE DH Key Exchange: name=MODP6144, bits=6144
  85. 000 algorithm IKE DH Key Exchange: name=MODP8192, bits=8192
  86. 000 algorithm IKE DH Key Exchange: name=DH19, bits=512
  87. 000 algorithm IKE DH Key Exchange: name=DH20, bits=768
  88. 000 algorithm IKE DH Key Exchange: name=DH21, bits=1056
  89. 000 algorithm IKE DH Key Exchange: name=DH22, bits=1024
  90. 000 algorithm IKE DH Key Exchange: name=DH23, bits=2048
  91. 000 algorithm IKE DH Key Exchange: name=DH24, bits=2048
  92. 000
  93. 000 stats db_ops: {curr_cnt, total_cnt, maxsz} :context={0,351381,64} trans={0,351381,6936} attrs={0,351381,4624}
  94. 000
  95. 000 Connection list:
  96. 000
  97. 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
  98. 000 "azure-to-hfoffice": oriented; my_ip=unset; their_ip=unset; my_updown=ipsec _updown;
  99. 000 "azure-to-hfoffice": xauth us:none, xauth them:none, my_username=[any]; their_username=[any]
  100. 000 "azure-to-hfoffice": our auth:secret, their auth:secret
  101. 000 "azure-to-hfoffice": modecfg info: us:none, them:none, modecfg policy:push, dns:unset, domains:unset, banner:unset, cat:unset;
  102. 000 "azure-to-hfoffice": labeled_ipsec:no;
  103. 000 "azure-to-hfoffice": policy_label:unset;
  104. 000 "azure-to-hfoffice": ike_life: 3600s; ipsec_life: 28800s; replay_window: 32; rekey_margin: 540s; rekey_fuzz: 100%; keyingtries: 0;
  105. 000 "azure-to-hfoffice": retransmit-interval: 500ms; retransmit-timeout: 60s;
  106. 000 "azure-to-hfoffice": initial-contact:no; cisco-unity:no; fake-strongswan:no; send-vendorid:no; send-no-esp-tfc:no;
  107. 000 "azure-to-hfoffice": policy: PSK+ENCRYPT+TUNNEL+PFS+UP+IKEV1_ALLOW+IKEV2_ALLOW+SAREF_TRACK+IKE_FRAG_ALLOW+ESN_NO;
  108. 000 "azure-to-hfoffice": conn_prio: 24,24; interface: eth0; metric: 0; mtu: unset; sa_prio:auto; sa_tfc:none;
  109. 000 "azure-to-hfoffice": nflog-group: unset; mark: unset; vti-iface:unset; vti-routing:no; vti-shared:no; nic-offload:auto;
  110. 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
  111. 000 "azure-to-hfoffice": dpd: action:hold; delay:0; timeout:0; nat-t: encaps:auto; nat_keepalive:yes; ikev1_natt:both
  112. 000 "azure-to-hfoffice": newest ISAKMP SA: #630097; newest IPsec SA: #630098;
  113. 000 "azure-to-hfoffice": IKE algorithms: AES_CBC_256-HMAC_SHA1-MODP1024
  114. 000 "azure-to-hfoffice": IKE algorithm newest: AES_CBC_256-HMAC_SHA1-MODP1024
  115. 000 "azure-to-hfoffice": ESP algorithms: AES_CBC_256-HMAC_SHA1_96
  116. 000 "azure-to-hfoffice": ESP algorithm newest: AES_CBC_256-HMAC_SHA1_96; pfsgroup=<Phase1>
  117. 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
  118. 000 "azure-to-idc": oriented; my_ip=unset; their_ip=unset; my_updown=ipsec _updown;
  119. 000 "azure-to-idc": xauth us:none, xauth them:none, my_username=[any]; their_username=[any]
  120. 000 "azure-to-idc": our auth:secret, their auth:secret
  121. 000 "azure-to-idc": modecfg info: us:none, them:none, modecfg policy:push, dns:unset, domains:unset, banner:unset, cat:unset;
  122. 000 "azure-to-idc": labeled_ipsec:no;
  123. 000 "azure-to-idc": policy_label:unset;
  124. 000 "azure-to-idc": ike_life: 3600s; ipsec_life: 28800s; replay_window: 32; rekey_margin: 540s; rekey_fuzz: 100%; keyingtries: 0;
  125. 000 "azure-to-idc": retransmit-interval: 500ms; retransmit-timeout: 60s;
  126. 000 "azure-to-idc": initial-contact:no; cisco-unity:no; fake-strongswan:no; send-vendorid:no; send-no-esp-tfc:no;
  127. 000 "azure-to-idc": policy: PSK+ENCRYPT+TUNNEL+PFS+IKEV1_ALLOW+IKEV2_ALLOW+SAREF_TRACK+IKE_FRAG_ALLOW+ESN_NO;
  128. 000 "azure-to-idc": conn_prio: 24,24; interface: eth0; metric: 0; mtu: unset; sa_prio:auto; sa_tfc:none;
  129. 000 "azure-to-idc": nflog-group: unset; mark: unset; vti-iface:unset; vti-routing:no; vti-shared:no; nic-offload:auto;
  130. 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
  131. 000 "azure-to-idc": dpd: action:hold; delay:0; timeout:0; nat-t: encaps:auto; nat_keepalive:yes; ikev1_natt:both
  132. 000 "azure-to-idc": newest ISAKMP SA: #630099; newest IPsec SA: #630074;
  133. 000 "azure-to-idc": IKE algorithms: AES_CBC_256-HMAC_SHA1-MODP1024
  134. 000 "azure-to-idc": IKE algorithm newest: AES_CBC_256-HMAC_SHA1-MODP1024
  135. 000 "azure-to-idc": ESP algorithms: AES_CBC_256-HMAC_SHA1_96
  136. 000 "azure-to-idc": ESP algorithm newest: AES_CBC_256-HMAC_SHA1_96; pfsgroup=<Phase1>
  137. 000
  138. 000 Total IPsec connections: loaded 2, active 2
  139. 000
  140. 000 State Information: DDoS cookies not required, Accepting new IKE connections
  141. 000 IKE SAs: total(2), half-open(0), open(0), authenticated(2), anonymous(0)
  142. 000 IPsec SAs: total(2), authenticated(2), anonymous(0)
  143. 000
  144. 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
  145. 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
  146. 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
  147. 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
  148. 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
  149. 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
  150. 000
  151. 000 Bare Shunt list:
  152. 000

六、激活隧道

进行ping测试激活隧道

 

七、排错

1、无法通信可能是因为ASA inside端口错误

2、两端加密方式需配置一致

3、默认IKE v1协议

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/391719
推荐阅读
相关标签
  

闽ICP备14008679号