For a Synology NAS to setup OpenVPN is not as easy as I thought it would be. Specifically when you enable client site certificate checking it’s not a tick in the box. Below the steps I follow to get it working.
first thing is to setup my own CA so I can create and sign my own server and client certificates. I used an awesome tool for this on github. clone it, then change variables as needed.
git clone https://github.com/OpenVPN/easy-rsa.git
cp vars.example vars
in the vars I updates for example the following fields;
set_var EASYRSA_DN "org"
set_var EASYRSA_REQ_COUNTRY "NL"
set_var EASYRSA_REQ_PROVINCE "California"
set_var EASYRSA_REQ_CITY "San Francisco"
set_var EASYRSA_REQ_ORG "Copyleft Certificate Co"
set_var EASYRSA_REQ_EMAIL "email@example.com"
set_var EASYRSA_REQ_OU "My Organizational Unit"
set_var EASYRSA_CA_EXPIRE 3650
set_var EASYRSA_CERT_EXPIRE 825
After changing the vars you can create your own PKI CA. Following commands initialize PKI and generate the CA. The CA is important so choose your passphrase wise! If this gets compromised, other certificates can be used to sign client certificates.
Generate Server Certificate and key
Generate a server certificate and key.
./easyrsa build-server-full synology_NAS_OpenVPN nopass
Two files will be generated, you need these later to upload to your NAS.
Generate Client Certificate and key
Generate a client certificate and key. Or more when you need more devices to connect to the VPN.
./easyrsa build-client-full client_peter nopass
Two files will be generated, you need these later to upload to your device which will connect to the laptop.
Install VPNServer package on Synology NAS
Now you need VPN Server package on your Synology NAS. Go the the admin page, e.g. https://192.168.1.1:5001/ and go to Package Center > All Packages. Search for VPN Server and click install when found. After installing, don’t run it yet. If already running, click stop. If your remote working on current VPN, please don’t ;)
Now you also need to SSH to you NAS to manual set OpenVPN to listen only to clients with certificate. Otherwise this whole extra certificate (2FA) can just be bypassed.
SSH to you NAS and edit the file below
remove the line or comment it with a #
Upload Certificate to Synology NAS
To upload them to you NAS, go the the admin page, e.g. https://192.168.1.1:5001/ and go to Control Pannel > Security > Certificate. then click Add
- Add a new certificate
- Import certificate
- Private key: use file
- Certificate: use file
- Intermediate certificate: use file
- Private key: use file
- click OK
then again in Control Pannel > Security > Certificate. but now click Configure. select the correct just uploaded certificate behind VPN Server. Now, go back to the package center and click Run for the VPN Server package. If you skip this (restarting VPN Server) you might will talk the VPN Server which is still serving previous certificate.
VPN Server settings on Synology NAS
Now the correct certificate is uploaded and VPN Server is started, you can change some last setting if needed, like;
- Privilege: Use for a specific VPN user might be a wise Idea, and only give that uses privilegse to OpenVPN
- OpenVPN: tick Enable OpenVPN server and change setting if wanted.
You now could click Export Configuration but this configuration is incomplete/incorrect. Therefor I generated my own OpenVPN config.
Generate Client OpenVPN config
I used the following configuration for the client. named it
VPNConfig-client-peter.ovpn. Be aware this file contains your private key (so this is your 2FA), store it securely or trough it away after setting up the OpenVPN.
remote <YOUR PUBLIC IP> 1194
redirect-gateway def1 # if you want all traffic tunneled
... input from easy-rsa/easyrsa3/pki/ca.crt
... input from easy-rsa/easyrsa3/pki/issued/client_peter.crt
-----BEGIN PRIVATE KEY-----
... input from easy-rsa/easyrsa3/pki/private/client_peter.crt
-----END PRIVATE KEY-----
Install OpenVPN Connect
Download https://openvpn.net/vpn-client/ and use the above file to connect. and login with user credentials you have given privileges to use OpenVPN (see above)
That should do it. Good luck!