[WireGuard] Comments on wgserver.service

Bruno Wolff III bruno at wolff.to
Wed Jul 6 14:04:10 CEST 2016

While wgserver.service is going to need some customization for each 
instance, there are a couple of things you might want to change in the 

If for whatever reason wgserver is left setup, starting and restarting 
the service will fail until the device is manually removed.
Adding the following as the first ExecStart will help:
ExecStart=-/bin/ip link del dev wgserver
That will attempt to clean up any left over device as part of the 
startup process. Which will keep:
ExecStartPre=/usr/sbin/ip link add dev wg0 type wireguard
from failing (exit status 2 if the device already exists) and aborting 
the service startup.

Also according to the systemd documentation, ExecStopPost commands are 
supposed to be run when starting fails. It doesn't seem to actually work 
this way on Fedora and I have filed a bug about it. But it may still 
be better to change:
ExecStop=/bin/ip link del dev wgserver
ExecStopPost=/bin/ip link del dev wgserver

Another note, that I'm not sure there is a standard fix for, but might 
be worth throwing in something for, is that if your config has a host 
name in it, you need functioning DNS when the service starts. And hence 
one may want to add Requires= and After= for a DNS service in some cases.

The example was helpful to me in figuring out the service files I am 
actually using on my two endpoints.

More information about the WireGuard mailing list