Difference between revisions of "OpenVPN server on Windows"

From Teltonika Networks Wiki
(43 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
==Introduction==
 
==Introduction==
  
{{Template:openvpn 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.
 
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.
Line 10: Line 10:
  
 
'''Prerequisites''':
 
'''Prerequisites''':
 
+
* A PC or Laptop running on Windows 7 or a later version
*A PC or Laptop running on Windows 7 or a later version
+
* The PC in question must have a '''[[Private_and_Public_IP_Addresses#Public_IP_address|Public IP address]]'''
*The computer in question must have a '''[[Private_and_Public_IP_Addresses#Public_IP_address|Public IP address]]'''
+
* An active Internet connection
*And an active Internet connection
 
 
 
 
----
 
----
 
'''Objective''':
 
'''Objective''':
Line 20: Line 18:
 
The purpose of this article is to provide the know-how needed to configure a working OpenVPN server on a Windows PC.
 
The purpose of this article is to provide the know-how needed to configure a working OpenVPN server on a Windows PC.
  
{{Template:installing openvpn software}}
+
==Step 1: installing OpenVPN software==
{{Template:preparing easyrsa}}
 
{{Template:generating certificates and keys}}
 
  
==Step 4: OpenVPN server configuration==
+
<ul>
 
+
<li>
In this section we'll be discussing how to configure an OpenVPN Tunnel (TUN) server that uses:
+
The first thing that we'll need 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.
*The UDP protocol
+
</li>
*TLS authentication
 
 
 
As a template, we'll be using the sample configuration file that comes along with the OpenVPN installation, but we'll be adding with some minor changes to it. You can find it in the ''OpenVPN'' installation directory, ''sample-config'' folder (default: ''C:\Program Files\OpenVPN\sample-config'') under the name '''''server.ovpn'''''.
 
 
----
 
----
<ul>
+
<li>
  <li>When you locate the file, make a copy, rename it and place it in the '''''config''''' directory of the OpenVPN folder (default path: ''C:\Program Files\OpenVPN\config''). You should also copy the certificates and keys to this directory (required files: ''ca.crt'', ''server.crt'', ''server.key'', ''dh2048.pem'').
+
'''Important note''': at one point before the installation begins, 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]]
  <li>Open the config file with a text editor. You can use the Notepad, but for editing configuration files we recommend using '''Notepad++''' for a better experience (you can download it from '''[https://notepad-plus-plus.org/download/v7.5.8.html here]''').
+
</li>
  </li>
+
</ul>
  <li>Locate the following lines:
 
    <ul>
 
      <pre>ca ca.crt
 
cert server.crt
 
key server.key
 
dh dh1024.pem</pre>
 
    </ul>
 
  </li>
 
  <li>Edit the lines in a way that corresponds with the actual file paths. The defaults used in this example are:
 
    <ul>
 
      <pre>ca "C:\\Program Files\\OpenVPN\\config\\ca.crt"
 
cert "C:\\Program Files\\OpenVPN\\config\\server.crt"
 
key "C:\\Program Files\\OpenVPN\\config\\server.key"
 
dh "C:\\Program Files\\OpenVPN\\config\\dh2048.pem"</pre>
 
    </ul>
 
'''NOTE''': Diffie Hellman parameters file name will depend on the key size that you specified in the ''vars.bat'' file. Don't forget to change it accordingly.
 
  </li>
 
  <li>Next comes the preferential configurations, i.e., whether you want UDP or TCP, Tunnel or Bridge, server's network, keep alive, cipher values, etc. You should configure these options in accordance with your needs. Bellow is an image of what the final configuration from this example looks like (with the comments present in the sample deleted file for more clarity):
 
    <ul>[[File:Openvpn windows server setup step 4 server config.png]]
 
    </ul>
 
The following changes were made to the sample file:
 
    <ul>
 
      <li>Changed ''udp'' to ''udp4'' to indicate that the connection should use only IPv4</li>
 
      <li>Added ''client-config-dir'' option for possible TLS client configuration</li>
 
      <li>Changed the ''ifconfig-pool-persist'' file path</li>
 
      <li>Changes to the certificate and key file paths</li><li>Note: cipher AES-256-CBC is deprecated in v.2.5. Change CBC to GCM
 
</li><li>You can harden (add security) to the VPN by creating a ta.key (''openvpn--genkey --secret keys/ta.key'') file on the server, placing it in the config folder and copying it to the config folder of all client machines.
 
</li><li>Edit the server.ovpn file found in the OpenVPN/sample-config folder. Lines that begin with # or ; will be ignored.) Feel free to change it however you want.</li></ul>
 
  </li></ul>
 
 
 
==Step 5: configuring clients==
 
 
 
Install OpenVPN on all client machines, but omit Steps 2, 3 and 4 above. Just copy the ca.crt , client.crt and client.key files already created on the server machine in Step 4 above to the config folder of the relevant client machine.
 
  
The next step is to create a configuration file for the clients. Edit the client.ovpn file found in the sample-config folder and save it.  Now open the separate article: '''[[OpenVPN client on Windows]],''' but note that only the latter part is relevant to this page. Begin at the line "• Save the file with an '''.ovpn''' extension."
+
==Step 2: generating TLS certificates and keys==
 
 
Note: The edited client.ovpn file can be copied to all the client machines unless specific changes need to be made.
 
 
 
==Step 6: launching the server==
 
 
 
If you've followed all the steps until now, your OpenVPN server configuration is complete! The next thing to do is to simply launch the server.
 
  
 
<ul>
 
<ul>
  <li>Run the '''OpenVPN GUI''' application  '''as administrator''' in order for the application to be able to fill log files.</li>
+
<li>
  <li>Locate OpenVPN GUI in the Windows system tray. Right click it and click '''Connect''':
+
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>
[[File:Openvpn windows server setup step 6 launching the server.png]]
+
[[File:How to generate tls certificates windows part 1 v2.png]]
    </ul>
+
----
  </li>
+
<li>
 +
Change the current directory to the EasyRSA folder. To do so, execute this command: <br>
 +
<pre>
 +
cd "C:\Program Files\OpenVPN\easy-rsa"
 +
</pre>
 +
</li>
 +
----
 +
<li>
 +
Initialize the OpenVPN configuration with the following command: <br>
 +
<pre>
 +
init-config
 +
</pre>
 +
</li>
 +
----
 +
<li>
 +
Open the '''''vars.bat''''' file with the Notepad text editor: <br>
 +
<pre>
 +
notepad vars.bat
 +
</pre>
 +
</li>
 +
----
 +
<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>
 +
<pre>
 +
set KEY_COUNTRY=US
 +
set KEY_PROVINCE=CA
 +
set KEY_CITY=SanFrancisco
 +
set KEY_ORG=OpenVPN
 +
 +
</pre>
 +
</li>
 +
----
 +
<li>
 +
You can also set the size for the Diffie Hellman parameters: <br>
 +
<pre>
 +
set DH_KEY_SIZE=2048
 +
</pre>
 +
</li>
 +
----
 +
<li>
 +
Once you're done, save the file and close the editor
 +
</li>
 +
----
 +
<li>
 +
Run the following commands: <br>
 +
<pre>
 +
vars
 +
</pre>
 +
<pre>
 +
clean-all
 +
</pre>
 +
</li>
 +
----
 +
<li>
 +
Now we can start generating the certificates. Begin with the '''certificate authority''' ('''CA''') file: <br>
 +
<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'''.
 +
</li>
 +
----
 +
<li>
 +
Next, build the '''server''' certificate and key: <br>
 +
<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".
 +
</li>
 +
----
 +
<li>
 +
Next, build certificates and keys for the '''clients''': <br>
 +
<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.
 +
</li>
 +
----
 +
<li>Lastly, generate '''Diffie Hellman parameters''': <br>
 +
<pre>
 +
build-dh
 +
</pre>
 +
</li>
 
</ul>
 
</ul>
 +
==Step 3: OpenVPN server configuration==
  
==See also==
+
*
 
 
*[[OpenVPN client on Windows]]
 
*[[OpenVPN configuration examples]]
 
*[[OpenVPN traffic split]]
 
 
 
==External links==
 
 
 
*OpenVPN downloads: https://openvpn.net/index.php/open-source/downloads.html
 
*OpenVPN manual: https://openvpn.net/index.php/open-source/documentation/manuals.html
 
*Notepad++ downloads: https://notepad-plus-plus.org/download/v7.5.8.html
 
[[Category:Windows]]
 

Revision as of 10:55, 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 need 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 begins, 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