本文主要是介绍SWAN之ikev2协议mobike-virtual-ip-nat配置测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本测试主要验证mobike功能,远程用户alice与网关sun建立连接时,首先使用eth1接口的IP地址发起连接,在建立连接之后,禁用eth1,以便连接可更新到eth0接口上。其中alice主机的两个接口与sun网关之间都是可达的,最后再次启用eth1接口,由于开启了最佳路径选择功能(charon.prefer_best_path),连接又回到eth1上。本次测试拓扑如下:
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-virtual-ip-nat/hosts/alice/etc/ipsec.conf,内容如下。这里leftsourceip指定为%config,表示由网关获取虚拟IP地址。
conn mobikeleftsourceip=%configleftcert=aliceCert.pemleftid=alice@strongswan.orgright=PH_IP_SUNrightid=@sun.strongswan.orgrightsubnet=10.2.0.0/16auto=add
alice的配置文件:ikev2/mobike-virtual-ip-nat/hosts/alice/etc/strongswan.conf,内容如下。选项prefer_best_path等于yes,表示在启用MOBIKE支持后,charon将尝试使用最佳的安全连接路径。默认情况下此值为0,即charon将保持当前的连接路径。
charon {load = random nonce aes sha1 sha2 pem pkcs1 curve25519 gmp x509 curl revocation hmac stroke kernel-netlink socket-defaultprefer_best_path = yessyslog {daemon {knl = 2}}
}
sun网关的配置文件:ikev2/mobike-virtual-ip-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-virtual-ip-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-virtual-ip-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.*INSTALLED.*ESP SPIs::YES
sun:: ipsec status 2> /dev/null::mobike.*INSTALLED.*ESP SPIs::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主机上检查连接的建立情况,此时连接在PH_IP_ALICE(10.1.0.10)和PH_IP_SUN(192.168.0.2)之间建立,最后使用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 status 2> /dev/null::mobike.*INSTALLED.*ESP in UDP SPIs::YES
sun:: ipsec status 2> /dev/null::mobike.*INSTALLED.*ESP in UDP SPIs::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接口,可见连接又回到了alice接口eth1的IP地址192.168.0.50和PH_IP_SUN之间。由于配置了虚拟IP地址10.3.0.3,连接变化时,IPsec策略不需要改变。
alice::ifup eth1::No output expected::NO
alice::sleep 1::No output expected::NO
alice::ping -c 1 PH_IP_BOB::64 bytes from PH_IP_BOB: icmp_.eq=1::YES
alice::ipsec status 2> /dev/null::mobike.*ESTABLISHED.*192.168.0.50.*PH_IP_SUN::YES
sun:: ipsec status 2> /dev/null::mobike.*ESTABLISHED.*PH_IP_SUN.*192.168.0.50::YES
alice::ipsec status 2> /dev/null::mobike.*INSTALLED.*ESP SPIs::YES
sun:: ipsec status 2> /dev/null::mobike.*INSTALLED.*ESP SPIs::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
以下为在建立连接的IKE_AUTH消息中,alice主机发送的mobike-virtual-ip-nat的支持,以及额外的IP地址信息,这里是:10.1.0.10(接口eth0的地址)。
以下为alice主机上strongswan进程的日志信息。在第二次启用eth1接口时,删除eth0之上的虚拟IP地址,并且安装到eth1接口上。增加安全策略,由于此安全策略与之前eth0接口添加的安全策略相同,此处增加引用计数,所以在删除之前out方向的安全策略时,其引用计数不为0,实际上并不删除。使用192.168.0.50(eth1接口)作为和对端192.168.0.2通信的源地址。
alice charon: 11[KNL] 192.168.0.50 is on interface eth1
alice charon: 11[KNL] deleting virtual IP 10.3.0.3
alice charon: 11[KNL] virtual IP 10.3.0.3 installed on eth1
alice charon: 11[KNL] adding policy 10.2.0.0/16 === 10.3.0.3/32 in [priority 375423, refcount 1]
alice charon: 11[KNL] adding policy 10.2.0.0/16 === 10.3.0.3/32 fwd [priority 375423, refcount 1]
alice charon: 11[KNL] policy 10.3.0.3/32 === 10.2.0.0/16 out already exists, increasing refcount
alice charon: 11[KNL] updating policy 10.3.0.3/32 === 10.2.0.0/16 out [priority 375423, refcount 2]
alice charon: 11[KNL] getting a local address in traffic selector 10.3.0.3/32
alice charon: 11[KNL] using host 10.3.0.3
alice charon: 11[KNL] getting iface name for index 4
alice charon: 11[KNL] using 192.168.0.2 as nexthop and eth1 as dev to reach 192.168.0.2/32
alice charon: 11[KNL] deleting policy 10.3.0.3/32 === 10.2.0.0/16 out
alice charon: 11[KNL] policy still used by another CHILD_SA, not removed
alice charon: 11[KNL] not updating policy 10.3.0.3/32 === 10.2.0.0/16 out [priority 375423, refcount 1]
alice charon: 05[KNL] getting iface index for eth1
alice charon: 10[KNL] fe80::5054:ff:fe3b:cd7 appeared on eth1
alice charon: 08[KNL] getting iface index for eth1
alice charon: 08[KNL] creating roam job due to address/link change
alice charon: 08[KNL] using 192.168.0.50 as address to reach 192.168.0.2/32
alice charon: 08[IKE] sending address list update using MOBIKE
alice charon: 08[KNL] using 192.168.0.50 as address to reach 192.168.0.2/32
alice charon: 08[ENC] generating INFORMATIONAL request 6 [ N(ADD_4_ADDR) N(ADD_6_ADDR) N(ADD_6_ADDR) ]
alice charon: 08[KNL] using 192.168.0.50 as address to reach 192.168.0.2/32
alice charon: 08[NET] sending packet: from 192.168.0.50[4500] to 192.168.0.2[4500] (128 bytes)
alice charon: 16[NET] received packet: from 192.168.0.2[4500] to 192.168.0.50[4500] (80 bytes)
alice charon: 16[ENC] parsed INFORMATIONAL response 6 [ ]
strongswan测试版本: 5.8.1
END
这篇关于SWAN之ikev2协议mobike-virtual-ip-nat配置测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!