This script automates the process of connecting your Synology NAS to the most recommended VPN server provided by NordVPN. It fetches the current top-recommended servers, checks against configured VPNs on your NAS, and connects to the best available option.
- Fetch Recommendations: The script starts by fetching the latest recommended servers from NordVPN's API.
- Check Configured VPNs: It then checks which of these recommended servers are already configured on your NAS.
- Connect: If a match is found, it connects your NAS to the highest recommended server.
Users can modify the script to change the number of recommended servers it considers by adjusting the list slicing in the get_recommended_servers
function. For example, to consider more servers, increase the range of the list returned.
To run this script, ensure that your Synology NAS is running at least DSM 7.2 and has Python and Requests installed.
To ensure the script runs smoothly on your Synology NAS, Python must be installed. Here’s how to install Python using the DSM Package Center:
- Access your Synology NAS via a web browser.
- Open Package Center:
- Navigate to the main menu and click on Package Center.
- Search for Python:
- In the Package Center, use the search bar to search for "Python".
- Install Python 3:
- Find the Python 3 package and click Install. This will install Python along with its script environment.
- SSH into your NAS.
- Install
requests
: Assuming Python is installed, you can install therequests
library using pip. If pip is not installed, first install it:Then installwget https://bootstrap.pypa.io/get-pip.py python3 get-pip.py
requests
:pip3 install requests
After installations, verify that requests
can be imported successfully in your Python environment:
python3 -c "import requests; print(requests.__version__)"
This command should print the version of requests
without errors, confirming it's correctly installed.
NB: Modify this script to replace with the user on your DSM before execution.
Before using the script, you need to set up VPN profiles on your NAS.
The VPN profiles must be named according to the servers recommended by NordVPN, e.g., au701_nordvpn_com_upd
.
-
Download Configuration Files: Go to NordVPN OVPN Configurations and download the OpenVPN configuration files for the servers you want to use.
-
Set Up VPN Profiles: Follow the detailed guide provided by WunderTech on setting up NordVPN on a Synology NAS at this link.
- Upload the script to your NAS: You can use any SCP client to transfer the script file to your NAS.
- Run the script:
python3 autoswitch-vpn.py
To make the script run every 3 hours on a Synology NAS running DSM 7.2, you can follow these steps to set up a scheduled task using the Task Scheduler in the DSM Control Panel.
- Access DSM Control Panel
- Login to your Synology NAS via a web browser.
- Open the Control Panel by clicking on the menu icon in the top left corner.
- Open Task Scheduler
- In the Control Panel, locate and click on Task Scheduler under the System section.
- Create a New Scheduled Task
- Click on the Create button and select Scheduled Task followed by User-defined script.
- Configure the Task
- Task: Give your task a name, e.g., "Connect to Recommended VPN".
- User: Select root from the drop-down menu for sufficient permissions.
- Run command: Input the command to run your script, e.g.,
/usr/bin/python3 /path/to/your/script/autoswitch-vpn.py
If you encounter issues, verify that:
- VPN profiles are correctly named and configured.
- The script has the necessary permissions to execute and modify VPN configurations.
- All Python dependencies are properly installed.
- Ensure executable permissions are granted to the script:
chmod +x /path/to/your/script/autoswitch-vpn.py
This setup ensures that your NAS always connects to the optimal server based on the current load, enhancing both the performance and security of your network connections.