Difference between revisions of "OpenVPN server on Windows"

From Teltonika Networks Wiki
Line 20: Line 20:
 
==Step 1: installing OpenVPN software==
 
==Step 1: installing OpenVPN software==
  
* The first thing that we'll to do is to install the necessary software needed in order to run an OpenVPN server. You can download the OpenVPN installer file from '''[https://openvpn.net/index.php/open-source/downloads.html here]'''. <br> Simply run the downloaded file and follow the instructions of the installation guide.
+
<ul>
 +
<li>
 +
The first thing that we'll to do is to install the necessary software needed in order to run an OpenVPN server. You can download the OpenVPN installer file from '''[https://openvpn.net/index.php/open-source/downloads.html here]'''. <br> Simply run the downloaded file and follow the instructions of the installation guide.
 +
</li>
 
----
 
----
* '''Important note''': at one point before the installation process, you will be prompted to select which components should be included in the installation. Make sure to select '''EasyRSA''' as it will be needed later on to generate keys and certificates. You can leave the rest as defaults:
+
<li>
 
+
'''Important note''': at one point before the installation process, you will be prompted to select which components should be included in the installation. Make sure to select '''EasyRSA''' as it will be needed later on to generate keys and certificates. You can leave the rest as defaults:
 +
</li>
 
[[File:Openvpn windows server setup step 1 openvpn installation part 1.png]]
 
[[File:Openvpn windows server setup step 1 openvpn installation part 1.png]]
 
+
</ul>
 
==Step 2: generating TLS certificates and keys==
 
==Step 2: generating TLS certificates and keys==
  
* Now we'll need to generate TLS certificates that will later be used for authentication purposes when clients connect to the OpenVPN server. For this we'll be using the '''EasyRSA''' application that was installed along with OpenVPN. <br> EasyRSA commands have to be executed via the Windows Command Prompt. It can be opened by typing '''cmd''' in the Windows search bar ('''Windows button + S'''). When you launch it, make sure you run it '''as administrator''':
+
<ul>
 
+
<li>
 +
Now we'll need to generate TLS certificates that will later be used for authentication purposes when clients connect to the OpenVPN server. For this we'll be using the '''EasyRSA''' application that was installed along with OpenVPN. <br> EasyRSA commands have to be executed via the Windows Command Prompt. It can be opened by typing '''cmd''' in the Windows search bar ('''Windows button + S'''). When you launch it, make sure you run it '''as administrator''':
 +
</li>
 
[[File:How to generate tls certificates windows part 1 v2.png]]
 
[[File:How to generate tls certificates windows part 1 v2.png]]
 
----
 
----
* Change the current directory to the EasyRSA folder. To do so, execute this command:
+
<li>
 
+
Change the current directory to the EasyRSA folder. To do so, execute this command: <br>
cd "C:\Program Files\OpenVPN\easy-rsa"
+
<pre>
 +
cd "C:\Program Files\OpenVPN\easy-rsa"
 +
</pre>
 +
</li>
 
----
 
----
* Initialize the OpenVPN configuration with the following command:
+
<li>
 
+
Initialize the OpenVPN configuration with the following command: <br>
init-config
+
<pre>
 +
init-config
 +
</pre>
 +
</li>
 
----
 
----
* Open the '''''vars.bat''''' file with the Notepad text editor:
+
<li>
 
+
Open the '''''vars.bat''''' file with the Notepad text editor: <br>
notepad vars.bat
+
<pre>
 +
notepad vars.bat
 +
</pre>
 +
</li>
 
----
 
----
* This is the template file for generating certificates, i.e., the information stored here will be offered as default values during certificate generation. Locate and edit the following lines in accordance with your needs:
+
<li>
 
+
This is the template file for generating certificates, i.e., the information stored here will be offered as default values during certificate generation. Locate and edit the following lines in accordance with your needs: <br>
set KEY_COUNTRY=US
+
<pre>
set KEY_PROVINCE=CA
+
set KEY_COUNTRY=US
set KEY_CITY=SanFrancisco
+
set KEY_PROVINCE=CA
set KEY_ORG=OpenVPN
+
set KEY_CITY=SanFrancisco
+
set KEY_ORG=OpenVPN
 +
 +
</pre>
 +
</li>
 
----
 
----
* You can also set the size for the Diffie Hellman parameters:
+
<li>
 
+
You can also set the size for the Diffie Hellman parameters: <br>
set DH_KEY_SIZE=2048
+
<pre>
 +
set DH_KEY_SIZE=2048
 +
</pre>
 +
</li>
 
----
 
----
* Once you're done, save the file and close the editor
+
<li>
 +
Once you're done, save the file and close the editor
 +
</li>
 
----
 
----
* Run the following commands:
+
<li>
 
+
Run the following commands: <br>
vars
+
<pre>
clean-all
+
vars
 +
</pre>
 +
<pre>
 +
clean-all
 +
</pre>
 +
</li>
 
----
 
----
* Now we can start generating the certificates. Begin with the '''certificate authority''' ('''CA''') file:
+
<li>
 
+
Now we can start generating the certificates. Begin with the '''certificate authority''' ('''CA''') file: <br>
build-ca
+
<pre>
 
+
build-ca
 +
</pre>
 
'''NOTE''': you can press the "Enter" key when prompted to enter the values set in the ''vars.bat'' file earlier. Doing this will set the values to the default specified in ''vars.bat''. However, you should type in a meaningful '''Common Name'''.
 
'''NOTE''': you can press the "Enter" key when prompted to enter the values set in the ''vars.bat'' file earlier. Doing this will set the values to the default specified in ''vars.bat''. However, you should type in a meaningful '''Common Name'''.
 +
</li>
 
----
 
----
* Next, build the '''server''' certificate and key:
+
<li>
 
+
Next, build the '''server''' certificate and key: <br>
build-key-server server
+
<pre>
 
+
build-key-server server
 +
</pre>
 
'''NOTE''': once again, don't forget to specify a different Common Name (use the name "server" for easier management purposes). When prompted the sign and commit the certificate, type '''y''' and press "Enter".
 
'''NOTE''': once again, don't forget to specify a different Common Name (use the name "server" for easier management purposes). When prompted the sign and commit the certificate, type '''y''' and press "Enter".
 +
</li>
 
----
 
----
* Next, build certificates and keys for the '''clients''':
+
<li>
 
+
Next, build certificates and keys for the '''clients''': <br>
build-key Client1
+
<pre>
 
+
build-key Client1
 +
</pre>
 
'''TIP''': use the same Common Name as the certificate name (Client1 in this example). This will help you differentiate different clients easier. Pick meaningful names like "toms_PC", "company_maintenance", etc. Repeat this step as many times as you need, depending on the client quantity.
 
'''TIP''': use the same Common Name as the certificate name (Client1 in this example). This will help you differentiate different clients easier. Pick meaningful names like "toms_PC", "company_maintenance", etc. Repeat this step as many times as you need, depending on the client quantity.
 +
</li>
 
----
 
----
* Lastly, generate '''Diffie Hellman parameters''':
+
<li>Lastly, generate '''Diffie Hellman parameters''': <br>
 
+
<pre>
build-dh
+
build-dh
 
+
</pre>
 +
</li>
 +
</ul>
 
==Step 3: OpenVPN server configuration==
 
==Step 3: OpenVPN server configuration==
  
 
*
 
*

Revision as of 10:54, 17 September 2018

Main Page > General Information > Configuration Examples > PC > Windows > OpenVPN server on Windows

Introduction

OpenVPN is an open-source software application that implements virtual private network (VPN) techniques for creating secure point-to-point or site-to-site connections in routed or bridged configurations and remote access facilities.

This article contains step-by-step instructions on how to create and run an OpenVPN server on a PC that runs on Windows OS. The information provided here is geared towards users of almost any knowledge level. The instructions apply to Windows 7 and newer systems.

Configuration overview and prerequisites

Before we begin, let's overview the configuration that we are attempting to achieve and the prerequisites that make it possible.

Prerequisites:

  • A PC or Laptop running on Windows 7 or a later version
  • The PC in question must have a Public IP address
  • An active Internet connection

Objective:

The purpose of this article is to provide the know-how needed to configure a working OpenVPN server on a Windows PC.

Step 1: installing OpenVPN software

  • The first thing that we'll to do is to install the necessary software needed in order to run an OpenVPN server. You can download the OpenVPN installer file from here.
    Simply run the downloaded file and follow the instructions of the installation guide.

  • Important note: at one point before the installation process, you will be prompted to select which components should be included in the installation. Make sure to select EasyRSA as it will be needed later on to generate keys and certificates. You can leave the rest as defaults:
  • Openvpn windows server setup step 1 openvpn installation part 1.png

Step 2: generating TLS certificates and keys

  • Now we'll need to generate TLS certificates that will later be used for authentication purposes when clients connect to the OpenVPN server. For this we'll be using the EasyRSA application that was installed along with OpenVPN.
    EasyRSA commands have to be executed via the Windows Command Prompt. It can be opened by typing cmd in the Windows search bar (Windows button + S). When you launch it, make sure you run it as administrator:
  • How to generate tls certificates windows part 1 v2.png
  • Change the current directory to the EasyRSA folder. To do so, execute this command:
    cd "C:\Program Files\OpenVPN\easy-rsa"
    

  • Initialize the OpenVPN configuration with the following command:
    init-config
    

  • Open the vars.bat file with the Notepad text editor:
    notepad vars.bat
    

  • This is the template file for generating certificates, i.e., the information stored here will be offered as default values during certificate generation. Locate and edit the following lines in accordance with your needs:
    set KEY_COUNTRY=US
    set KEY_PROVINCE=CA
    set KEY_CITY=SanFrancisco
    set KEY_ORG=OpenVPN
    set [email protected]
    

  • You can also set the size for the Diffie Hellman parameters:
    set DH_KEY_SIZE=2048
    

  • Once you're done, save the file and close the editor

  • Run the following commands:
    vars
    
    clean-all
    

  • Now we can start generating the certificates. Begin with the certificate authority (CA) file:
    build-ca
    

    NOTE: you can press the "Enter" key when prompted to enter the values set in the vars.bat file earlier. Doing this will set the values to the default specified in vars.bat. However, you should type in a meaningful Common Name.


  • Next, build the server certificate and key:
    build-key-server server
    

    NOTE: once again, don't forget to specify a different Common Name (use the name "server" for easier management purposes). When prompted the sign and commit the certificate, type y and press "Enter".


  • Next, build certificates and keys for the clients:
    build-key Client1
    

    TIP: use the same Common Name as the certificate name (Client1 in this example). This will help you differentiate different clients easier. Pick meaningful names like "toms_PC", "company_maintenance", etc. Repeat this step as many times as you need, depending on the client quantity.


  • Lastly, generate Diffie Hellman parameters:
    build-dh
    

Step 3: OpenVPN server configuration