服务器使用 systemd 自动启动 wireguard

Generate a valid and working WireGuard configuration file /etc/wireguard/wg0.conf. Our setup guide offers details. Note: You may have to replace the Endpoint hostname with the WireGuard server IP address in the WireGuard configuration file. DNS may or may not be applied when systemd brings the wg0 interface up. Add the WireGuard service to systemd sudo systemctl enable wg-quick@wg0.service sudo systemctl daemon-reload Start the new service immediately: sudo systemctl start wg-quick@wg0

  1. Generate a valid and working WireGuard configuration file /etc/wireguard/wg0.conf. Our setup guide offers details. Note: You may have to replace the Endpoint hostname with the WireGuard server IP address in the WireGuard configuration file. DNS may or may not be applied when systemd brings the wg0 interface up.
  2. Add the WireGuard service to systemd
1
2
sudo systemctl enable wg-quick@wg0.service
sudo systemctl daemon-reload
  1. Start the new service immediately:
1
sudo systemctl start wg-quick@wg0
  1. Reboot your computer system to verify the automatic connection on startup works as expected.
  2. Check the service status:
1
systemctl status wg-quick@wg0
  1. To remove the service and clean up the system:
1
2
3
4
5
sudo systemctl stop wg-quick@wg0
sudo systemctl disable wg-quick@wg0.service
sudo rm -i /etc/systemd/system/wg-quick@wg0*
sudo systemctl daemon-reload
sudo systemctl reset-failed

References


服务器使用 systemd 自动启动 wireguard
https://www.frytea.com/post/20230328073404.html
作者
Tianlun Song
发布于
2023年3月28日
更新于
2024年6月10日
许可协议