本文主要是介绍SWAN之ikev2协议mobike-nat配置测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本测试主要验证mobike-nat功能,远程用户alice与网关sun建立连接时,首先使用eth1接口的IP地址发起连接,在建立连接之后,禁用eth1,以便连接可更新到eth0接口上。其中alice主机的两个接口与sun网关之间都是可达的,alice的eth0接口与sun网关之后有NAT设备moon路由器。此环境中为远程用户配置虚拟IP地址,即使连接地址发送变化,IPsec策略也可保持不变。本次测试拓扑如下:
eth1 |--------| 192.168.0.50 | alice |-------------------------------------------| |--------| | | eth0 || 10.1.0.10 || || eth0 | eth0 |------------| |--------| 192.168.0.1 |------------| 192.168.0.1 |--------| |------------|| test-br1 |---------| moon |---------------| test-br0 |--------------| sun |---------------| test-br2 ||------------| |--------| |------------| |--------| eth1 |------------|| eth1 | 10.2.0.1 || 10.1.0.1 | || | || | || 10.1.0.20 192.168.0.100 | 192.168.0.200 10.2.0.10 | |--------| |--------| | |--------| |--------| | venus | | carol |------|------| dave | | bob | |--------| |--------| |--------| |--------|
主机配置
alice的配置文件:ikev2/mobike-nat/hosts/alice/etc/ipsec.conf,内容如下。这里leftsourceip指定为%config,表示由网关获取虚拟IP地址。
conn mobikeleft=192.168.0.50leftsourceip=%configleftcert=aliceCert.pemleftid=alice@strongswan.orgright=PH_IP_SUNrightid=@sun.strongswan.orgrightsubnet=10.2.0.0/16auto=add
sun网关的配置文件:ikev2/mobike-nat/hosts/sun/etc/ipsec.conf,内容如下。指定为alice主机分配虚拟IP地址10.3.0.3。
conn mobikeleft=PH_IP_SUNleftcert=sunCert.pemleftid=@sun.strongswan.orgleftsubnet=10.2.0.0/16right=%anyrightsourceip=10.3.0.3rightid=alice@strongswan.orgauto=add
测试准备阶段
配置文件:ikev2/mobike-nat/pretest.dat,内容为通常的ipsec连接的启动语句。另外需要注意的是启用alice的eth1接口,此次测试使用此接口发起连接。位于路径中间的moon路由器,设置NAT规则。
alice::ifup eth1
moon::iptables -t nat -A POSTROUTING -o eth0 -s 10.1.0.0/16 -p udp -j SNAT --to-source PH_IP_MOON:1024-1100
moon::iptables -t nat -A POSTROUTING -o eth0 -s 10.1.0.0/16 -p tcp -j SNAT --to-source PH_IP_MOON:2000-2100
测试阶段
配置文件:ikev2/mobike-nat/evaltest.dat内容如下。在确认alice主机和sun网关连接建立之后,在主机alice上检查ipsec statusall命令的输出内容,确认10.3.0.3(虚拟IP)到10.2.0.0/16网段的连接,然后使用ping命令测试到bob主机的连通性。
alice::ipsec status 2> /dev/null::mobike.*ESTABLISHED.*PH_IP_ALICE1.*PH_IP_SUN::YES
sun:: ipsec status 2> /dev/null::mobike.*ESTABLISHED.*PH_IP_SUN.*PH_IP_ALICE1::YES
alice::ipsec statusall 2> /dev/null::10.3.0.3/32 === 10.2.0.0/16::YES
sun:: ipsec statusall 2> /dev/null::10.2.0.0/16 === 10.3.0.3/32::YES
alice::ping -c 1 PH_IP_BOB::64 bytes from PH_IP_BOB: icmp_.eq=1::YES
接下来,禁用eth1接口,使用ipsec status命令在alice和sun主机上检查连接的建立情况,最后使用ping命令测试到主机bob的连通性。
alice::ifdown eth1::No output expected::NO
alice::sleep 1::No output expected::NO
alice::ipsec status 2> /dev/null::mobike.*ESTABLISHED.*PH_IP_ALICE.*PH_IP_SUN::YES
sun:: ipsec status 2> /dev/null::mobike.*ESTABLISHED.*PH_IP_SUN.*PH_IP_MOON::YES
alice::ipsec statusall 2> /dev/null::10.3.0.3/32 === 10.2.0.0/16::YES
sun:: ipsec statusall 2> /dev/null::10.2.0.0/16 === 10.3.0.3/32::YES
alice::ping -c 1 PH_IP_BOB::64 bytes from PH_IP_BOB: icmp_.eq=1::YES
以下为在建立连接的IKE_AUTH消息中,alice主机发送的mobike-nat的支持,以及额外的IP地址信息,这里是:10.1.0.10(接口eth0的地址)。
以下为alice主机上strongswan进程的日志信息。在检测到eth1禁用,其地址192.168.0.50(IPv6:fe80::5054:ff:fe3b:cd7)不可用之后,查找到对端地址192.168.0.2(sun网关)的路由,重新选择可达的源地址。这里选择的是eth0接口的地址10.1.0.10,由于对端sun网关通告了两个地址:192.168.0.2和10.2.0.1,分别检测alice到这两个地址的路径。最后,向192.168.0.2发送地址更新消息。
地址更新消息中将发送NAT-D字段,以检测是否有NAT设备,由于在此路径上有NAT设备moon路由器,发送NAT保活报文。
alice charon: 12[KNL] 192.168.0.50 disappeared from eth1
alice charon: 09[KNL] interface eth1 deactivated
alice charon: 14[KNL] fec0::5 disappeared from eth1
alice charon: 15[KNL] fe80::5054:ff:fe3b:cd7 disappeared from eth1
alice charon: 16[IKE] old path is not available anymore, try to find another
alice charon: 16[IKE] looking for a route to 192.168.0.2 ...
alice charon: 16[IKE] requesting address change using MOBIKE
alice charon: 16[ENC] generating INFORMATIONAL request 2 [ ]
alice charon: 16[IKE] checking path 10.1.0.10[4500] - 192.168.0.2[4500]
alice charon: 16[NET] sending packet: from 10.1.0.10[4500] to 192.168.0.2[4500] (80 bytes)
alice charon: 16[IKE] checking path 10.1.0.10[4500] - 10.2.0.1[4500]
alice charon: 16[NET] sending packet: from 10.1.0.10[4500] to 10.2.0.1[4500] (80 bytes)
alice charon: 09[NET] received packet: from 192.168.0.2[4500] to 10.1.0.10[4500] (80 bytes)
alice charon: 09[ENC] parsed INFORMATIONAL response 2 [ ]
alice charon: 09[KNL] error uninstalling route installed with policy 10.3.0.3/32 === 10.2.0.0/16 out
alice charon: 09[ENC] generating INFORMATIONAL request 3 [ N(UPD_SA_ADDR) N(NATD_S_IP) N(NATD_D_IP) N(COOKIE2) N(ADD_6_ADDR) ]
alice charon: 09[NET] sending packet: from 10.1.0.10[4500] to 192.168.0.2[4500] (192 bytes)
alice charon: 11[NET] received packet: from 192.168.0.2[4500] to 10.1.0.10[4500] (160 bytes)
alice charon: 11[ENC] parsed INFORMATIONAL response 3 [ N(NATD_S_IP) N(NATD_D_IP) N(COOKIE2) ]
alice charon: 11[IKE] local host is behind NAT, sending keep alives
下图为报文中的地址更新消息
以下为alice主机上执行ipsec statusall的输出信息。可见由于使用了虚拟IP地址10.3.0.3,即使连接地址发送改变,ESP隧道保持不变,变化前后的SPI值相同。
Connections:mobike: 192.168.0.50...192.168.0.2 IKEv2mobike: local: [alice@strongswan.org] uses public key authenticationmobike: cert: "C=CH, O=strongSwan Project, OU=Sales, CN=alice@strongswan.org"mobike: remote: [sun.strongswan.org] uses public key authenticationmobike: child: dynamic === 10.2.0.0/16 TUNNEL
Security Associations (1 up, 0 connecting):mobike[1]: ESTABLISHED 1 second ago, 10.1.0.10[alice@strongswan.org]...192.168.0.2[sun.strongswan.org]mobike[1]: IKEv2 SPIs: 29154b69c025bb3c_i* a1cba9e6fead4f44_r, public key reauthentication in 53 minutesmobike[1]: IKE proposal: AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/CURVE_25519mobike{1}: INSTALLED, TUNNEL, reqid 1, ESP in UDP SPIs: ca44b6bc_i cdc82104_omobike{1}: AES_CBC_128/HMAC_SHA2_256_128, 168 bytes_i (2 pkts, 0s ago), 168 bytes_o (2 pkts, 0s ago), rekeying in 15 minutesmobike{1}: 10.3.0.3/32 === 10.2.0.0/16
以下为alice主机上的安全策略信息。可见由于使用了虚拟IP地址10.3.0.3,即使连接地址发送改变,也无需删除或添加新策略,只需对策略的tmpl进行适当修改即可。
src 10.3.0.3/32 dst 10.2.0.0/16 uid 0dir out action allow index 633 priority 375423 ptype main share any flag (0x00000000)lifetime config:tmpl src 10.1.0.10 dst 192.168.0.2proto esp spi 0xcdc82104(3452444932) reqid 1(0x00000001) mode tunnellevel required share anyenc-mask ffffffff auth-mask ffffffff comp-mask ffffffff
src 10.2.0.0/16 dst 10.3.0.3/32 uid 0dir in action allow index 656 priority 375423 ptype main share any flag (0x00000000)tmpl src 192.168.0.2 dst 10.1.0.10proto esp spi 0x00000000(0) reqid 1(0x00000001) mode tunnellevel required share anyenc-mask ffffffff auth-mask ffffffff comp-mask ffffffff
strongswan测试版本: 5.8.1
END
这篇关于SWAN之ikev2协议mobike-nat配置测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!