OpenVPN as a server on Windows
Before you read this post, familiarize yourself with the basics of running a VPN server on a home PC. These basics are explained in Helping friends in foreign countries. Most of that post applies to all home VPN servers, even if the clients are actually in the same country as you.
You can then proceed to install OpenVPN as a server on your PC.
We use Windows as a sample client at the end of this tutorial, but OpenVPN client software also exists for Linux, macOS, Android, and iOS.
Decisions
Decide whether your clients will access your PC by IP address or by DNS name.
In the examples in this post, we have used the DNS name alice.cscot.buzz
.
Decide on a protocol and port for your clients to reach your PC. OpenVPN supports both TCP and UDP. TCP is more reliable, whereas UDP is faster. If clients are subject to censorship, you may have heard about the old trick of using TCP on port 443. This rarely works against modern firewalls.
We will use UDP on port 1194
in our examples.
Open your PC’s firewall
We are using udp/1194
for client input. You should have already opened that port on your router and forwarded it to your PC. Now open that port for input in the Windows firewall like this:
- In the Windows search box, type
firewall
. - Select Windows Defender Firewall with Advanced Security.
- In the left pane, select Inbound Rules.
- In the right pane, select New Rule.
- Type is Port. Click Next.
- Type is UDP, and specific local port as
1194
. Click Next. - Action is Allow. Click Next.
- Leave all domains checked. Click Next.
- Set the Name to
OpenVPN Inbound
. - Click Finish.
When you are done, close Windows Defender Firewall with Advanced Security.
Install OpenVPN
Open your browser, and go to the OpenVPN Community Downloads page at https://openvpn.net/community-downloads.
Download the Windows 64-bit MSI installer. Run the installer.
Don’t install immediately. Make sure you click the Customize button first.
- Deselect the OpenVPN GUI, but make sure the OpenVPN Service remains selected
- Select the EasyRSA 3 Certificate Management Scripts
Click Install now.
When the installation is complete, click Close.
Initialize public key infrastructure
The installer has placed the EasyRSA 3 Certificate Management Scripts in C:\Program Files\OpenVPN\easy-rsa
.
In the Windows search box, type cmd
. Right-click on the Command Prompt app, and select Run as administrator.
Enter the command:
1 | cd C:\Program Files\OpenVPN\easy-rsa |
Open an Easy-RSA shell:
1 | EasyRSA-Start.bat |
Initialize your public key infrastructure by entering the command:
1 | ./easyrsa init-pki |
Your newly created public key infrastructure directory is C:\Program Files\OpenVPN\easy-rsa\pki
. It has a variables file named vars
inside it.
Optionally, launch Notepad with the Run as administrator option, and edit C:\Program Files\OpenVPN\easy-rsa\pki\vars
to your liking. Save the file if you edited it.
Create Certification Authority
Create your CA. Inside the Easy-RSA shell enter the command:
1 | ./easyrsa build-ca nopass |
You are promoted for a Common Name. If you just press Enter, the Common Name defaults to Easy-RSA CA
.
Your new CA certificate file is created at C:/Program Files/OpenVPN/easy-rsa/pki/ca.crt
.
Build server certificate and key
Build a server certificate and key. In our example, the server will be named alice
.
1 | ./easyrsa build-server-full alice nopass |
You are asked to type the word yes
to confirm the details.
The certificate is created at C:/Program Files/OpenVPN/easy-rsa/pki/issued/alice.crt
. The inline file, which we will not use in this tutorial, is created at C:/Program Files/OpenVPN/easy-rsa/pki/inline/alice.inline
.
Build client certificate(s) and key(s)
For each client, build a client certificate and key. In our example, the first client will be named bob
:
1 | ./easyrsa build-client-full bob nopass |
You are asked to type the word yes
to confirm the details.
The certificate is created at C:/Program Files/OpenVPN/easy-rsa/pki/issued/bob.crt
. In this tutorial, we will use the automatically generated inline file to make it easier to construct a client .ovpn
file. The inline file is created at C:/Program Files/OpenVPN/easy-rsa/pki/inline/bob.inline
.
Build Diffie-Hellman parameters
The Diffie-Hellman parameters are used only by an OpenVPN server. They are not needed on the client(s).
1 | ./easyrsa gen-dh |
After the generation process, the Diffie-Hellman parameters of size 2048 are created at C:/Program Files/OpenVPN/easy-rsa/pki/dh.pem
.
Build TLS encryption key
Open a browser. Download the most recent Easy-TLS source code .zip
file from https://github.com/TinCanTech/easy-tls/releases.
Unzip the .zip
file.
Copy the file easytls
into C:\Program Files\OpenVPN\easy-rsa
. You need administrator permissions to do this.
Back inside the Easy-RSA shell in the Command Prompt window, initialize Easy-TLS:
1 | ./easytls init-tls |
Build a TLS crypt v1 key:
1 | ./easytls build-tls-crypt |
The TLS crypt v1 key is created at C:/Program Files/OpenVPN/easy-rsa/pki/easytls/tls-crypt.key
.
Exit the Easy-RSA shell:
1 | exit |
Close the Command Prompt window for now.
Create server configuration file
Launch Notepad running as administrator.
Using the following as a model for your configuration. Of course, you must change values such as protocol (udp
), port (1194
), and server name (alice
) to match your choices.
1 | dev tun |
When you are done editing, save the file as C:\Program Files\OpenVPN\config-auto\alice.ovpn
. Make sure you use the directory name config-auto
and that Notepad does not add .txt
to the end of the file name.
Close Notepad.
Enable forwarding
Open Control Panel > Network and Internet > Network and Sharing Center > Change adapter settings.
You will see that the installation has created a new network adapter described as TAP-Windows Adapter V9
. It will have a name such as OpenVPN TAP-Windows 6
.
Now open a Command Prompt window running as administrator. Determine the interface number of OpenVPN TAP-Windows 6
(or whatever name applies in your case) as follows. Issue the command:
1 | netsh int ipv4 show int |
Note down the interface index number of OpenVPN TAP-Windows 6
(in our example). In our example, the interface index number was 11
.
See if forwarding is enabled. For example, if your interface index is 11
:
1 | netsh int ipv4 show int 11 | findstr "Forwarding" |
If forwarding is disabled, then enable forwarding by issuing the command:
1 | netsh int ipv4 set int 11 Forwarding="enabled" |
Double-check the results show Forwarding is enabled:
1 | netsh int ipv4 show int 11 | findstr "Forwarding" |
Close the Command Prompt window for now.
Close the Control Panel for now.
Enable routing
In the Windows search box, type regedit
, right-click Registry Editor, and select Run as administrator. In the left pane, navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
.
Find IPEnableRouter
of type REG_DWORD
.
Set its value to 1
.
Click OK.
Close Registry Editor.
Start services
In the Windows search box, type services
, right-click the Services app, and select Run as administrator.
Find the row for Routing and Remote Access
.
- Right-click on it, and select Properties.
- Set the Startup type to Automatic.
- Click Apply.
- Click Start.
- Click OK.
Locate the row for OpenVPN Interactive service
.
- Right-click, and select Properties.
- Click Stop.
- Change its Startup type to Manual.
- Click Apply.
- Click OK.
Locate the row for OpenVPNService
.
- Stop the service.
- Start the service.
Close the Services app.
Open Windows File Explorer. Navigate to C:\Program Files\OpenVPN\log
. Check the log file alice.log
for any error messages. It should show Initialization Sequence Completed
.
Share Internet adapter
Go to Windows Control Panel > Network and Internet > Network and Sharing Center > Change adapter settings.
On your main Internet network adapter (i.e. Ethernet or wireless), right-click, and select Properties.
Select the Sharing tab.
Check the box for Allow other network users to connect through this computer’s internet connection.
Select OpenVPN TAP-Windows 6
.
Click OK.
Disable and enable TAP-Windows Adapter V9
On the OpenVPN TAP-Windows 6
adapter (or whatever your TAP-Windows Adapter V9 is named), right-click, then disable and re-enable the adapter.
Close the Network Connections window.
Close the Control Panel windows.
Create client configuration
In Notepad, create a configuration file for the client. Model it on the following.
- You will need to change the remote DNS name or IP address to match your situation.
- Copy and paste in your inline certificates and keys from
C:/Program Files/OpenVPN/easy-rsa/pki/inline/bob.inline
. - Copy and paste in your TLS encryption key from
C:/Program Files/OpenVPN/easy-rsa/pki/easytls/tls-crypt.key
1 | client |
Save the file in your server’s Documents
folder as bob.ovpn
.
Securely copy client ovpn file to client PC
Securely copy bob.ovpn
from the server’s Documents
folder to the client’s Downloads
folder.
You can use any secure tool to do the copy.
- If both server and client are nearby, you can use a USB memory stick.
- For a remote server, you can use the Remote Desktop Connection (RDC) app with local disk access enabled.
- Or you can just copy and paste from Notepad on an RDC session with the server down to Notepad on your local client.
However you do the secure copy, you will end up with a file bob.ovpn
in your client PC Downloads
folder.
Set up Windows client
Switch to working on the client PC.
From the OpenVPN Downloads page at https://openvpn.net/community-downloads, download the 64-bit installer for Windows.
Run the installer. On the client, you need the OpenVPN GUI component, but you do not need the EasyRSA 3 Certificatre Management scripts. These are the defaults.
The installer places an OpenVPN GUI shortcut icon on your desktop.
Double-click the OpenVPN GUI shortcut icon on your desktop.
A message appears to say that there are as yet no readable connection profiles (i.e., configurations). Click OK.
Import bob.ovpn
as follows:
- Right-click on the OpenVPN icon in the system tray.
- Select Import file.
- Select the
bob.ovpn
file from yourDownloads
folder. - You should see a message indicating that the file was imported successfully.
- Click OK.
Right-click on the OpenVPN icon in the system tray, and select Connect. If problems occur, check C:\Users\<YOUR-USER-NAME>\OpenVPN\log\bob.log
for any error messages.
On successful connect, a notification appears to say you are now connected.
The OpenVPN icon in the system tray turns green.