How to autostart Wireguard (wg-quick) on boot on Alpine Linux

If you have a Wireguard config file such as /etc/wireguard/wghome.conf, which you can start manually using wg-quick up wghome, this is how you autostart it on boot. Thanks to Justin Ludwig on Serverfault for the template for that init script

Create /etc/init.d/wg-quick-wghome:

wg_quick_openrc_init.sh
#!/sbin/openrc-run
description="wg-quick wghome"

depend() {
    need net
    need localmount
}

start() {
    wg-quick up schlaftier
}

stop() {
    wg-quick down schlaftier
}

Then make it executable:

example.sh
chmod a+x /etc/init.d/wg-quick-wghome

and enable it to start on boot:

example.sh
rc-update add wg-quick-wghome default

and start it right now if desired:

example.sh
/etc/init.d/wg-quick-wghome start

Of course you can add multiple scripts like this. Just ensure to name them differently and perform all the steps required to enable startup on boot.


Check out similar posts by category: Alpine Linux, Networking, Wireguard