【问题标题】:strongswan configuration and traffic on tunnel problem IKEv2关于隧道问题 IKEv2 的 strongswan 配置和流量
【发布时间】:2021-01-26 03:06:28
【问题描述】:

我是这个范围内的新手。我尝试在谷歌云平台上使用 centos7(不同区域)配置 strongswan 站点到站点。我已经按照这个指南做了:

  1. https://blog.ruanbekker.com/blog/2018/02/11/setup-a-site-to-site-ipsec-vpn-with-strongswan-and-preshared-key-authentication/
  2. https://www.tecmint.com/setup-ipsec-vpn-with-strongswan-on-centos-rhel-8/
  3. https://medium.com/@georgeswizzalonge/how-to-setup-a-site-to-site-vpn-connection-with-strongswan-32d4ed034ae2

这个ipsec.conf来自站点A:

config setup
     charondebug="all"
     strictcrlpolicy=no
     uniqueids = yes

conn sg-to-jkt
    authby=secret
    left=%defaultroute
    leftid=34.xx.xx.xxx
    leftsubnet=10.xxx.x.xx/24
    right=34.xxx.xxx.xxx
    rightsubnet=10.xxx.x.x/24
    ike=aes256-sha2_256-modp1024!
    esp=aes256-sha2_256!
    keyingtries=0
    ikelifetime=1h
    lifetime=8h
    dpddelay=30
    dpdtimeout=120
    dpdaction=restart
    auto=start

ipsec.secrets档案站A:

site-A site-B : PSK "someencryptedkey"

这个ipsec.conf站点B:

config setup
         charondebug="all"
         strictcrlpolicy=no
         uniqueids = yes

conn jkt-to-sg
        authby=secret
        left=%defaultroute
        leftid=34.xxx.xxx.xxx
        leftsubnet=10.xxx.x.x/24
        right=34.xx.xx.xxx
        rightsubnet=10.xxx.x.xx/24
        ike=aes256-sha2_256-modp1024!
        esp=aes256-sha2_256!
        keyingtries=0
        ikelifetime=1h
        lifetime=8h
        dpddelay=30
        dpdtimeout=120
        dpdaction=restart
        auto=start

ipsec.secret文件站点B:

site-B site-A : PSK "someencryptedkey"

我的问题是:

  1. 为什么每次我重新启动 strongswan (strongswan restart),strongswan 服务 (systemctl status strongswan) 变得死/不活动? (注:strongswan隧道还在)

     ● strongswan.service - strongSwan IPsec IKEv1/IKEv2 daemon using ipsec.conf
    Loaded: loaded (/usr/lib/systemd/system/strongswan.service; enabled; vendor preset: disabled)
    Active: inactive (dead) since Sun 2020-10-11 16:37:06 UTC; 32min ago
    
  2. ESP 协议中没有流量,tcpdump esp 不显示任何内容,但 strongswan 隧道已启动。我意识到状态给出的结果与示例不同。结果返回ESP in UDP SPIs 而不是ESP SPIs。有什么不同或其他的吗?

感谢您的帮助和建议

【问题讨论】:

    标签: centos7 vpn systemctl strongswan


    【解决方案1】:

    您可以检查您的 Systemd 服务文件 strongswan.service 并更改 Type= 选项。

    默认情况下你应该有Type=simple,它适用于许多Systemd服务文件,但是当ExecStart中的脚本启动另一个进程并完成时它不起作用,请考虑更改为明确指定Type=forking [Service] 部分,以便 Systemd 知道查看生成的进程而不是初始进程。

    来自 man systemd.service:

    如果设置为分叉,则预计使用 ExecStart= 配置的进程将调用 fork() 作为其启动的一部分。当启动完成并设置所有通信通道时,父进程将退出。子进程继续作为主守护进程运行。这是传统 UNIX 守护程序的行为。如果使用此设置,建议也使用 PIDFile= 选项,以便 systemd 可以识别守护进程的主进程。 systemd 将在父进程退出后立即启动后续单元。

    另外,我发现another thread in StrackOverflow 也有类似的问题。

    但请参阅man systemd.service 以获取合适的类型。

    关于你的第二个问题,你可以检查你的防火墙,我在link 中发现了另一个类似的案例

    【讨论】:

    • 您好,谢谢您的回答。我已经检查了你所说的,strongswan 服务没有 Type 属性。我刚刚发现重新启动服务只需要使用“systemctl”而不是“systemctl + strongswan restart”。第二个答案的链接没有给我任何线索,但我发现对于带有“UDP SPI 中的 ESP”的隧道可以使用“tcpdump -i eth0 -n udp”检查流量。