Skip to content

Instantly share code, notes, and snippets.

@AdroitAdorKhan
Last active June 27, 2023 07:23
Show Gist options
  • Save AdroitAdorKhan/904ad82ad414a1d2fd3b2fe9644467b9 to your computer and use it in GitHub Desktop.
Save AdroitAdorKhan/904ad82ad414a1d2fd3b2fe9644467b9 to your computer and use it in GitHub Desktop.

Function to add a wireguard conf in /etc/wireguard/ dir with ease

wireguardConf() {
	conf=/etc/wireguard/${1}.conf
	if test -f "$conf"; then
		systemctl enable wg-quick@${1}.service
		systemctl daemon-reload
		systemctl start wg-quick@${1}
		systemctl status wg-quick@${1}
	fi
}

Usage wireguardConf <conf0>.conf

wireguardConf conf0

Add the service to systemd:

sudo systemctl enable wg-quick@cloudflare0.service
sudo systemctl daemon-reload

Start the service:

sudo systemctl start wg-quick@cloudflare0

Check status:

systemctl status wg-quick@cloudflare0

To remove the service and clean up the system:

sudo systemctl stop wg-quick@cloudflare0
sudo systemctl disable wg-quick@cloudflare0.service
sudo rm -i /etc/systemd/system/wg-quick@cloudflare0*
sudo systemctl daemon-reload
sudo systemctl reset-failed

Thanks - https://www.ivpn.net/knowledgebase/linux/linux-autostart-wireguard-in-systemd/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment