Prerequisites:
-
Ubuntu system with WireGuard installed and configured
-
Root access to your Ubuntu system
Create a new file with your favorite text editor, for example:
sudo nano ~/wg_auto_toggle.sh
Paste the following code into the file and save it.
sudo chmod +x ~/wg_auto_toggle.sh
Now, every time you run the script, it will automatically detect the status of your VPN and toggle it on or off as needed. You can run the script by executing:
sudo bash ~/wg.sh