CentOS7:需要重新启动 SoftEther VPN 接口才能获得静态 IP

CentOS7:需要重新启动 SoftEther VPN 接口才能获得静态 IP

我使用 SystemD 操作系统启动来启动我的 VPN 客户端(softEther),但在为 VPN 客户端网络接口的本地接口分配静态 IP 时遇到了麻烦。

这是我的 SystemD 配置:

    [Unit]
    Description=SoftEther VPN Client
    After=network.target auditd.service
    ConditionPathExists=!/usr/local/vpnclient/vpnclient/do_not_run

    [Service]
    Type=forking
    EnvironmentFile=-/usr/local/vpnclient/vpnclient
    ExecStart=/usr/local/vpnclient/vpnclient start
    ExecStop=/usr/local/vpnclient/vpnclient stop
    KillMode=process
    Restart=on-failure

    # Hardening
    PrivateTmp=yes
    ProtectHome=yes
    ProtectSystem=full
    ReadOnlyDirectories=/
    ReadWriteDirectories=-/usr/local/vpnclient/vpnclient
    CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_ADMIN CAP_SETUID

    [Install]
    WantedBy=multi-user.target

当我启动服务时,会出现本地界面,但没有我配置的静态 IP。

    vpn_softether: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet6 fe80::2ac:e9ff:fe7e:289e prefixlen 64 scopeid 0x20<link>
    ether 00:ac:e9:7e:28:9e txqueuelen 1000 (Ethernet)
    RX packets 12 bytes 864 (864.0 B)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 20 bytes 1632 (1.5 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

有我的 /etc/sysconfig/network-scripts/ifcfg-vpn_softether :

DEVICE="vpn_softether"
HWADDR="00:ac:e9:7e:28:9e"
ONBOOT="yes"
BOOTPROTO=static
NM_CONTROLLED="no"
IPADDR="10.38.0.50"
NETMASK="255.255.255.0"

我需要执行:

    ifdown vpn_softether && ifup vpn_softether

能够在接口上拥有我的静态IP:

    vpn_softether: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 10.38.0.50 netmask 255.255.255.0 broadcast 10.38.0.255
    inet6 fe80::2ac:e9ff:fe7e:289e prefixlen 64 scopeid 0x20<link>
    ether 00:ac:e9:7e:28:9e txqueuelen 1000 (Ethernet)
    RX packets 33 bytes 2506 (2.4 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 69 bytes 12308 (12.0 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

我会很感激一些提示:)

答案1

添加:

/usr/local/vpnclient/vpnclient start
ifdown vpn_softether && ifup vpn_softethe

到脚本,然后在 systemd 服务文件的 ExecStart 行引用创建的脚本

答案2

谢谢拉曼!

它可以帮助某人,有技巧。

修改后的systemD服务:

    [Unit]
    Description=SoftEther VPN Client
    After=network.target auditd.service
    ConditionPathExists=!/usr/local/vpnclient/vpnclient/do_not_run

    [Service]
    Type=forking
    EnvironmentFile=-/usr/local/vpnclient/vpnclient
    ExecStart=/usr/local/vpnclient/restart_vpn_eth.sh
    ExecStop=/usr/local/vpnclient/vpnclient stop
    KillMode=process
    Restart=on-failure

    # Hardening
    PrivateTmp=yes
    ProtectHome=yes
    ProtectSystem=full
    ReadOnlyDirectories=/
    ReadWriteDirectories=-/usr/local/vpnclient/vpnclient
    CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYS_ADMIN CAP_SETUID

    [Install]
    WantedBy=multi-user.target

和脚本:

    #!/bin/sh

    /usr/local/vpnclient/vpnclient start
    sleep 5
    ifdown vpn_cent
    sleep 5
    ifup vpn_cent

相关内容