linuxvpnwireguard

WireGuard VPN: wg0.conf does not exist


I am trying to setup VPN on my server with help of WireGuard. I am following this tutorial https://upcloud.com/resources/tutorials/get-started-wireguard-vpn

ERROR

systemctl status wg-quick@wg0
× wg-quick@wg0.service - WireGuard via wg-quick(8) for wg0
     Loaded: loaded (/lib/systemd/system/wg-quick@.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2023-07-17 08:31:15 UTC; 15h 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
   Main PID: 5700 (code=exited, status=1/FAILURE)
        CPU: 5ms

Jul 17 08:31:15 v1567418.hosted-by-vdsina.ru systemd[1]: Starting WireGuard via wg-quick(8) for wg0...
Jul 17 08:31:15 v1567418.hosted-by-vdsina.ru wg-quick[5700]: wg-quick: `/etc/wireguard/wg0.conf' does not exist
Jul 17 08:31:15 v1567418.hosted-by-vdsina.ru systemd[1]: wg-quick@wg0.service: Main process exited, code=exited, status=1/FAILURE
Jul 17 08:31:15 v1567418.hosted-by-vdsina.ru systemd[1]: wg-quick@wg0.service: Failed with result 'exit-code'.
Jul 17 08:31:15 v1567418.hosted-by-vdsina.ru systemd[1]: Failed to start WireGuard via wg-quick(8) for wg0.

My actions:

Uncommented line in file sudo nano /etc/sysctl.conf net.ipv4.ip_forward=1

Applied the change below

sudo sysctl -p

Configured /etc/wireguard/wg0.conf

[Interface]
Address = 10.66.66.1/24,fd42:42:42::1/64
ListenPort = 58723
PrivateKey = XXXXX


PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE;

PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE;


[Peer]
# Client Name: Unnamed
PublicKey = MY__PUB_KEY
AllowedIPs = 10.66.66.2/32,fd42:42:42::2/128

Then I am starting WG

> wg-quick up wg0
wg-quick: `wg0' already exists

Then I am enabling WG to start automatically

systemctl enable wg-quick@wg0

Solution

  • If it shows wg-quick: wg0' already exists, just run

    sudo wg-quick down wg0
    

    and then:

    sudo wg-quick up wg0