Wireguard 服务在启动时处于“非活动(死亡)”状态

Wireguard 服务在启动时处于“非活动(死亡)”状态

我有一个运行 Ubuntu 21.04 的 Raspberry Pi 4,使用系统安装的 Wireguard。它在启动时无法正确启动。我之前安装过 Ubuntu 20.10,也出现了同样的情况。

启动时:

$ systemctl status [email protected][email protected] - WireGuard via wg-quick(8) for wg0
     Loaded: loaded (/lib/systemd/system/[email protected]; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:wg-quick(8)
             man:wg(8)
             https://www.wireguard.com/
             https://www.wireguard.com/quickstart/
             https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
             https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8

从正在运行的系统:

$ systemctl start [email protected]

$ systemctl status [email protected][email protected] - WireGuard via wg-quick(8) for wg0
     Loaded: loaded (/lib/systemd/system/[email protected]; disabled; vendor preset: enabled)
     Active: active (exited) since Wed 2021-06-09 12:52:16 PDT; 2s ago
       Docs: man:wg-quick(8)
             man:wg(8)
             https://www.wireguard.com/
             https://www.wireguard.com/quickstart/
             https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
             https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
    Process: 2366 ExecStart=/usr/bin/wg-quick up wg0 (code=exited, status=0/SUCCESS)
   Main PID: 2366 (code=exited, status=0/SUCCESS)

Jun 09 12:52:15 pi4 systemd[1]: Starting WireGuard via wg-quick(8) for wg0...
Jun 09 12:52:15 pi4 wg-quick[2366]: [#] ip link add wg0 type wireguard
Jun 09 12:52:16 pi4 wg-quick[2366]: [#] wg setconf wg0 /dev/fd/63
Jun 09 12:52:16 pi4 wg-quick[2366]: [#] ip -4 address add 10.9.0.1/24 dev wg0
Jun 09 12:52:16 pi4 wg-quick[2366]: [#] ip link set mtu 1420 up dev wg0
Jun 09 12:52:16 pi4 wg-quick[2366]: [#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Jun 09 12:52:16 pi4 wg-quick[2366]: [#] ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Jun 09 12:52:16 pi4 systemd[1]: Finished WireGuard via wg-quick(8) for wg0.

$ cat /lib/systemd/system/[email protected]
[Unit]
Description=WireGuard via wg-quick(8) for %I
After=network-online.target nss-lookup.target
Wants=network-online.target nss-lookup.target
PartOf=wg-quick.target
Documentation=man:wg-quick(8)
Documentation=man:wg(8)
Documentation=https://www.wireguard.com/
Documentation=https://www.wireguard.com/quickstart/
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
Documentation=https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/wg-quick up %i
ExecStop=/usr/bin/wg-quick down %i
ExecReload=/bin/bash -c 'exec /usr/bin/wg syncconf %i <(exec /usr/bin/wg-quick strip %i)'
Environment=WG_ENDPOINT_RESOLUTION_RETRIES=infinity

[Install]
WantedBy=multi-user.target

答案1

看起来该服务已被禁用:

$ systemctl status [email protected][email protected] - WireGuard via wg-quick(8) for wg0
     Loaded: loaded (/lib/systemd/system/[email protected]; disabled; vendor preset: enabled)
                                                            ^^^^^^^^-- here

...启用它:

sudo systemctl enable [email protected]

相关内容