Changes between Initial Version and Version 1 of HOWTO


Ignore:
Timestamp:
07/25/14 07:08:33 (10 years ago)
Author:
Samuli Seppänen
Comment:

Migrate content from http://openvpn.net/index.php/open-source/documentation/howto.html

Legend:

Unmodified
Added
Removed
Modified
  • HOWTO

    v1 v1  
     1= Introduction =
     2
     3OpenVPN is a full-featured SSL VPN which implements OSI layer 2 or 3 secure network extension using the industry standard SSL/TLS protocol, supports flexible client authentication methods based on certificates, smart cards, and/or username/password credentials, and allows user or group-specific access control policies using firewall rules applied to the VPN virtual interface. OpenVPN is not a web application proxy and does not operate through a web browser.
     4
     5OpenVPN 2.0 expands on the capabilities of OpenVPN 1.x by offering a scalable client/server mode, allowing multiple clients to connect to a single OpenVPN server process over a single TCP or UDP port. OpenVPN 2.3 includes a large number of improvements, including full IPv6 support and PolarSSL support.
     6
     7This document provides step-by-step instructions for configuring an OpenVPN 2.x client/server VPN, including:
     8
     9[[TOC(inline, depth=1)]]
     10
     11The impatient may wish to jump straight to the sample configuration files:
     12
     13 * [https://github.com/OpenVPN/openvpn/blob/master/sample/sample-config-files/server.conf Server configuration file].
     14 * [https://github.com/OpenVPN/openvpn/blob/master/sample/sample-config-files/client.conf Client configuration file].
     15
     16= Intended Audience =
     17
     18This HOWTO assumes that readers possess a prior understanding of basic networking concepts such as IP addresses, DNS names, netmasks, subnets, IP routing, routers, network interfaces, LANs, gateways, and firewall rules.
     19
     20= Additional Documentation =
     21
     22The original [wiki:Openvpn1xHOWTO OpenVPN 1.x HOWTO] is still available, and remains relevant for point-to-point or static-key configurations.
     23
     24For additional documentation, have a look at the [wiki:WikiStart documentation front page].
     25
     26= OpenVPN Quickstart =
     27
     28While this HOWTO will guide you in setting up a scalable client/server VPN using an X509 PKI (public key infrastruction using certificates and private keys), this might be overkill if you are only looking for a simple VPN setup with a server that can handle a single client.
     29
     30If you would like to get a VPN running quickly with minimal configuration, you might check out the [wiki:StaticKeyMiniHowto Static Key Mini-HOWTO].
     31
     32
     33Static Key advantages
     34
     35    Simple Setup
     36    No X509 PKI (Public Key Infrastructure) to maintain
     37
     38Static Key disadvantages
     39
     40    Limited scalability -- one client, one server
     41    Lack of perfect forward secrecy -- key compromise results in total disclosure of previous sessions
     42    Secret key must exist in plaintext form on each VPN peer
     43    Secret key must be exchanged using a pre-existing secure channel
     44
     45Installing OpenVPN
     46
     47OpenVPN source code and Windows installers can be downloaded here. Recent releases (2.2 and later) are also available as Debian and RPM packages; see the OpenVPN wiki for details.
     48
     49For security, it's a good idea to check the file release signature after downloading.
     50
     51The OpenVPN executable should be installed on both server and client machines, since the single executable provides both client and server functions.
     52Linux Notes (using RPM package)
     53
     54If you are using a Linux distribution which supports RPM packages (SuSE, Fedora, Redhat, etc.), it's best to install using this mechanism. The easiest method is to find an existing binary RPM file for your distribution. You can also build your own binary RPM file:
     55
     56    rpmbuild -tb openvpn-[version].tar.gz
     57
     58Once you have the .rpm file, you can install it with the usual
     59
     60    rpm -ivh openvpn-[details].rpm
     61
     62or upgrade an existing installation with
     63
     64    rpm -Uvh openvpn-[details].rpm
     65
     66Installing OpenVPN from a binary RPM package has these dependencies:
     67
     68    openssl
     69    lzo
     70    pam
     71
     72Furthermore, if you are building your own binary RPM package, there are several additional dependencies:
     73
     74    openssl-devel
     75    lzo-devel
     76    pam-devel
     77
     78See the openvpn.spec file for additional notes on building an RPM package for Red Hat Linux 9 or building with reduced dependencies.
     79Linux Notes (without RPM)
     80
     81If you are using Debian, Gentoo, or a non-RPM-based Linux distribution, use your distro-specific packaging mechanism such as apt-get on Debian or emerge on Gentoo.
     82
     83It is also possible to install OpenVPN on Linux using the universal ./configure method. First expand the .tar.gz file:
     84
     85    tar xfz openvpn-[version].tar.gz
     86
     87Then cd to the top-level directory and type:
     88
     89    ./configure
     90    make
     91    make install
     92
     93Windows Notes
     94
     95OpenVPN for Windows can be installed from the self-installing exe file on the OpenVPN download page. Remember that OpenVPN will only run on Windows XP or later. Also note that OpenVPN must be installed and run by a user who has administrative privileges (this restriction is imposed by Windows, not OpenVPN). The restriction can be sidestepped by running OpenVPN in the background as a service, in which case even non-admin users will be able to access the VPN, once it is installed. More discussion on OpenVPN + Windows privilege issues.
     96
     97Official OpenVPN Windows installers include OpenVPN-GUI, which allows managing OpenVPN connections from a system tray applet. Other GUI applications are also available.
     98
     99After you've run the Windows installer, OpenVPN is ready for use and will associate itself with files having the .ovpn extension. To run OpenVPN, you can:
     100
     101    Right click on an OpenVPN configuration file (.ovpn) and select Start OpenVPN on this configuration file. Once running, you can use the F4key to exit.
     102
     103     
     104    Run OpenVPN from a command prompt Window with a command such as:
     105
     106     
     107
     108        openvpn myconfig.ovpn
     109
     110    Once running in a command prompt window, OpenVPN can be stopped by the F4 key.
     111    Run OpenVPN as a service by putting one or more .ovpn configuration files in \Program Files\OpenVPN\config and starting the OpenVPN Service, which can be controlled from Start Menu -> Control Panel -> Administrative Tools -> Services.
     112
     113Additional Windows install notes.
     114Mac OS X Notes
     115
     116Angelo Laub and Dirk Theisen have developed an OpenVPN GUI for OS X.
     117Other OSes
     118
     119Some notes are available in the INSTALL file for specific OSes. In general, the
     120
     121    ./configure
     122    make
     123    make install
     124
     125method can be used, or you can search for an OpenVPN port or package which is specific to your OS/distribution.
     126
     127Determining whether to use a routed or bridged VPN
     128
     129See FAQ for an overview of Routing vs. Ethernet Bridging. See also the OpenVPN Ethernet Bridging page for more notes and details on bridging.
     130
     131Overall, routing is probably a better choice for most people, as it is more efficient and easier to set up (as far as the OpenVPN configuration itself) than bridging. Routing also provides a greater ability to selectively control access rights on a client-specific basis.
     132
     133I would recommend using routing unless you need a specific feature which requires bridging, such as:
     134
     135    the VPN needs to be able to handle non-IP protocols such as IPX,
     136    you are running applications over the VPN which rely on network broadcasts (such as LAN games), or
     137    you would like to allow browsing of Windows file shares across the VPN without setting up a Samba or WINS server.
     138
     139Numbering private subnets
     140
     141Setting up a VPN often entails linking together private subnets from different locations.
     142
     143The Internet Assigned Numbers Authority (IANA) has reserved the following three blocks of the IP address space for private internets (codified in RFC 1918):
     14410.0.0.0        10.255.255.255  (10/8 prefix)
     145172.16.0.0      172.31.255.255  (172.16/12 prefix)
     146192.168.0.0     192.168.255.255         (192.168/16 prefix)
     147
     148While addresses from these netblocks should normally be used in VPN configurations, it's important to select addresses that minimize the probability of IP address or subnet conflicts. The types of conflicts that need to be avoided are:
     149
     150    conflicts from different sites on the VPN using the same LAN subnet numbering, or
     151    remote access connections from sites which are using private subnets which conflict with your VPN subnets.
     152
     153For example, suppose you use the popular 192.168.0.0/24 subnet as your private LAN subnet. Now you are trying to connect to the VPN from an internet cafe which is using the same subnet for its WiFi LAN. You will have a routing conflict because your machine won't know if 192.168.0.1 refers to the local WiFi gateway or to the same address on the VPN.
     154
     155As another example, suppose you want to link together multiple sites by VPN, but each site is using 192.168.0.0/24 as its LAN subnet. This won't work without adding a complexifying layer of NAT translation, because the VPN won't know how to route packets between multiple sites if those sites don't use a subnet which uniquely identifies them.
     156
     157The best solution is to avoid using 10.0.0.0/24 or 192.168.0.0/24 as private LAN network addresses. Instead, use something that has a lower probability of being used in a WiFi cafe, airport, or hotel where you might expect to connect from remotely. The best candidates are subnets in the middle of the vast 10.0.0.0/8 netblock (for example 10.66.77.0/24).
     158
     159And to avoid cross-site IP numbering conflicts, always use unique numbering for your LAN subnets.
     160
     161Setting up your own Certificate Authority (CA) and generating certificates and keys for an OpenVPN server and multiple clients
     162Overview
     163
     164The first step in building an OpenVPN 2.x configuration is to establish a PKI (public key infrastructure). The PKI consists of:
     165
     166    a separate certificate (also known as a public key) and private key for the server and each client, and
     167    a master Certificate Authority (CA) certificate and key which is used to sign each of the server and client certificates.
     168
     169OpenVPN supports bidirectional authentication based on certificates, meaning that the client must authenticate the server certificate and the server must authenticate the client certificate before mutual trust is established.
     170
     171Both server and client will authenticate the other by first verifying that the presented certificate was signed by the master certificate authority (CA), and then by testing information in the now-authenticated certificate header, such as the certificate common name or certificate type (client or server).
     172
     173This security model has a number of desirable features from the VPN perspective:
     174
     175    The server only needs its own certificate/key -- it doesn't need to know the individual certificates of every client which might possibly connect to it.
     176    The server will only accept clients whose certificates were signed by the master CA certificate (which we will generate below). And because the server can perform this signature verification without needing access to the CA private key itself, it is possible for the CA key (the most sensitive key in the entire PKI) to reside on a completely different machine, even one without a network connection.
     177    If a private key is compromised, it can be disabled by adding its certificate to a CRL (certificate revocation list). The CRL allows compromised certificates to be selectively rejected without requiring that the entire PKI be rebuilt.
     178    The server can enforce client-specific access rights based on embedded certificate fields, such as the Common Name.
     179
     180Note that the server and client clocks need to be roughly in sync or certificates might not work properly.
     181Generate the master Certificate Authority (CA) certificate & key
     182
     183In this section we will generate a master CA certificate/key, a server certificate/key, and certificates/keys for 3 separate clients.
     184
     185For PKI management, we will use easy-rsa, a set of scripts which is bundled with OpenVPN 2.2.x and earlier. If you're using OpenVPN 2.3.x, you need to download easy-rsa separately from here.
     186
     187If you are using Linux, BSD, or a unix-like OS, open a shell and cd to the easy-rsa subdirectory. If you installed OpenVPN from an RPM or DEB file, the easy-rsa directory can usually be found in /usr/share/doc/packages/openvpn or /usr/share/doc/openvpn (it's best to copy this directory to another location such as /etc/openvpn, before any edits, so that future OpenVPN package upgrades won't overwrite your modifications). If you installed from a .tar.gz file, the easy-rsa directory will be in the top level directory of the expanded source tree.
     188
     189If you are using Windows, open up a Command Prompt window and cd to \Program Files\OpenVPN\easy-rsa. Run the following batch file to copy configuration files into place (this will overwrite any preexisting vars.bat and openssl.cnf files):
     190
     191    init-config
     192
     193Now edit the vars file (called vars.bat on Windows) and set the KEY_COUNTRY, KEY_PROVINCE, KEY_CITY, KEY_ORG, and KEY_EMAIL parameters. Don't leave any of these parameters blank.
     194
     195Next, initialize the PKI. On Linux/BSD/Unix:
     196
     197    . ./vars
     198    ./clean-all
     199    ./build-ca
     200
     201On Windows:
     202
     203    vars
     204    clean-all
     205    build-ca
     206
     207The final command (build-ca) will build the certificate authority (CA) certificate and key by invoking the interactive openssl command:
     208
     209    ai:easy-rsa # ./build-ca
     210    Generating a 1024 bit RSA private key
     211    ............++++++
     212    ...........++++++
     213    writing new private key to 'ca.key'
     214    -----
     215    You are about to be asked to enter information that will be incorporated
     216    into your certificate request.
     217    What you are about to enter is what is called a Distinguished Name or a DN.
     218    There are quite a few fields but you can leave some blank
     219    For some fields there will be a default value,
     220    If you enter '.', the field will be left blank.
     221    -----
     222    Country Name (2 letter code) [KG]:
     223    State or Province Name (full name) [NA]:
     224    Locality Name (eg, city) [BISHKEK]:
     225    Organization Name (eg, company) [OpenVPN-TEST]:
     226    Organizational Unit Name (eg, section) []:
     227    Common Name (eg, your name or your server's hostname) []:OpenVPN-CA
     228    Email Address [me@myhost.mydomain]:
     229
     230Note that in the above sequence, most queried parameters were defaulted to the values set in the vars or vars.bat files. The only parameter which must be explicitly entered is the Common Name. In the example above, I used "OpenVPN-CA".
     231Generate certificate & key for server
     232
     233Next, we will generate a certificate and private key for the server. On Linux/BSD/Unix:
     234
     235    ./build-key-server server
     236
     237On Windows:
     238
     239    build-key-server server
     240
     241As in the previous step, most parameters can be defaulted. When the Common Name is queried, enter "server". Two other queries require positive responses, "Sign the certificate? [y/n]" and "1 out of 1 certificate requests certified, commit? [y/n]".
     242Generate certificates & keys for 3 clients
     243
     244Generating client certificates is very similar to the previous step. On Linux/BSD/Unix:
     245
     246    ./build-key client1
     247    ./build-key client2
     248    ./build-key client3
     249
     250On Windows:
     251
     252    build-key client1
     253    build-key client2
     254    build-key client3
     255
     256If you would like to password-protect your client keys, substitute the build-key-pass script.
     257
     258Remember that for each client, make sure to type the appropriate Common Name when prompted, i.e. "client1", "client2", or "client3". Always use a unique common name for each client.
     259Generate Diffie Hellman parameters
     260
     261Diffie Hellman parameters must be generated for the OpenVPN server. On Linux/BSD/Unix:
     262
     263    ./build-dh
     264
     265On Windows:
     266
     267    build-dh
     268
     269Output:
     270
     271    ai:easy-rsa # ./build-dh
     272    Generating DH parameters, 1024 bit long safe prime, generator 2
     273    This is going to take a long time
     274    .................+...........................................
     275    ...................+.............+.................+.........
     276    ......................................
     277
     278Key Files
     279
     280Now we will find our newly-generated keys and certificates in the keys subdirectory. Here is an explanation of the relevant files:
     281Filename        Needed By       Purpose         Secret
     282ca.crt  server + all clients    Root CA certificate     NO
     283ca.key  key signing machine only        Root CA key     YES
     284dh{n}.pem       server only     Diffie Hellman parameters       NO
     285server.crt      server only     Server Certificate      NO
     286server.key      server only     Server Key      YES
     287client1.crt     client1 only    Client1 Certificate     NO
     288client1.key     client1 only    Client1 Key     YES
     289client2.crt     client2 only    Client2 Certificate     NO
     290client2.key     client2 only    Client2 Key     YES
     291client3.crt     client3 only    Client3 Certificate     NO
     292client3.key     client3 only    Client3 Key     YES
     293
     294The final step in the key generation process is to copy all files to the machines which need them, taking care to copy secret files over a secure channel.
     295
     296Now wait, you may say. Shouldn't it be possible to set up the PKI without a pre-existing secure channel?
     297
     298 
     299
     300The answer is ostensibly yes. In the example above, for the sake of brevity, we generated all private keys in the same place. With a bit more effort, we could have done this differently. For example, instead of generating the client certificate and keys on the server, we could have had the client generate its own private key locally, and then submit a Certificate Signing Request (CSR) to the key-signing machine. In turn, the key-signing machine could have processed the CSR and returned a signed certificate to the client. This could have been done without ever requiring that a secret .key file leave the hard drive of the machine on which it was generated.
     301Creating configuration files for server and clients
     302Getting the sample config files
     303
     304It's best to use the OpenVPN sample configuration files as a starting point for your own configuration. These files can also be found in
     305
     306    the sample-config-files directory of the OpenVPN source distribution
     307    the sample-config-files directory in /usr/share/doc/packages/openvpn or /usr/share/doc/openvpn if you installed from an RPM or DEB package
     308    Start Menu -> All Programs -> OpenVPN -> OpenVPN Sample Configuration Files on Windows
     309
     310Note that on Linux, BSD, or unix-like OSes, the sample configuration files are named server.conf and client.conf. On Windows they are named server.ovpn and client.ovpn.
     311Editing the server configuration file
     312
     313The sample server configuration file is an ideal starting point for an OpenVPN server configuration. It will create a VPN using a virtual TUN network interface (for routing), will listen for client connections on UDP port 1194 (OpenVPN's official port number), and distribute virtual addresses to connecting clients from the 10.8.0.0/24 subnet.
     314
     315Before you use the sample configuration file, you should first edit the ca, cert, key, and dh parameters to point to the files you generated in the PKI section above.
     316
     317At this point, the server configuration file is usable, however you still might want to customize it further:
     318
     319    If you are using Ethernet bridging, you must use server-bridge and dev tap instead of server and dev tun.
     320    If you want your OpenVPN server to listen on a TCP port instead of a UDP port, use proto tcp instead of proto udp (If you want OpenVPN to listen on both a UDP and TCP port, you must run two separate OpenVPN instances).
     321    If you want to use a virtual IP address range other than 10.8.0.0/24, you should modify the server directive. Remember that this virtual IP address range should be a private range which is currently unused on your network.
     322    Uncomment out the client-to-client directive if you would like connecting clients to be able to reach each other over the VPN. By default, clients will only be able to reach the server.
     323    If you are using Linux, BSD, or a Unix-like OS, you can improve security by uncommenting out the user nobody and group nobody directives.
     324
     325If you want to run multiple OpenVPN instances on the same machine, each using a different configuration file, it is possible if you:
     326
     327    Use a different port number for each instance (the UDP and TCP protocols use different port spaces so you can run one daemon listening on UDP-1194 and another on TCP-1194).
     328    If you are using Windows, each OpenVPN configuration taneeds to have its own TAP-Windows adapter. You can add additional adapters by going to Start Menu -> All Programs -> TAP-Windows -> Add a new TAP-Windows virtual ethernet adapter.
     329    If you are running multiple OpenVPN instances out of the same directory, make sure to edit directives which create output files so that multiple instances do not overwrite each other's output files. These directives include log, log-append, status, and ifconfig-pool-persist.
     330
     331Editing the client configuration files
     332
     333The sample client configuration file (client.conf on Linux/BSD/Unix or client.ovpn on Windows) mirrors the default directives set in the sample server configuration file.
     334
     335    Like the server configuration file, first edit the ca, cert, and key parameters to point to the files you generated in the PKI section above. Note that each client should have its own cert/key pair. Only the cafile is universal across the OpenVPN server and all clients.
     336
     337     
     338    Next, edit the remotedirective to point to the hostname/IP address and port number of the OpenVPN server (if your OpenVPN server will be running on a single-NIC machine behind a firewall/NAT-gateway, use the public IP address of the gateway, and a port number which you have configured the gateway to forward to the OpenVPN server).
     339
     340     
     341    Finally, ensure that the client configuration file is consistent with the directives used in the server configuration. The major thing to check for is that the dev (tun or tap) and proto (udp or tcp) directives are consistent. Also make sure that comp-lzo and fragment, if used, are present in both client and server config files.
     342
     343     
     344
     345Starting up the VPN and testing for initial connectivity
     346Starting the server
     347
     348First, make sure the OpenVPN server will be accessible from the internet. That means:
     349
     350    opening up UDP port 1194 on the firewall (or whatever TCP/UDP port you've configured), or
     351    setting up a port forward rule to forward UDP port 1194 from the firewall/gateway to the machine running the OpenVPN server.
     352
     353Next, make sure that the TUN/TAP interface is not firewalled.
     354
     355To simplify troubleshooting, it's best to initially start the OpenVPN server from the command line (or right-click on the .ovpn file on Windows), rather than start it as a daemon or service:
     356
     357    openvpn [server config file]
     358
     359A normal server startup should look like this (output will vary across platforms):
     360
     361    Sun Feb  6 20:46:38 2005 OpenVPN 2.0_rc12 i686-suse-linux [SSL] [LZO] [EPOLL] built on Feb  5 2005
     362    Sun Feb  6 20:46:38 2005 Diffie-Hellman initialized with 1024 bit key
     363    Sun Feb  6 20:46:38 2005 TLS-Auth MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ]
     364    Sun Feb  6 20:46:38 2005 TUN/TAP device tun1 opened
     365    Sun Feb  6 20:46:38 2005 /sbin/ifconfig tun1 10.8.0.1 pointopoint 10.8.0.2 mtu 1500
     366    Sun Feb  6 20:46:38 2005 /sbin/route add -net 10.8.0.0 netmask 255.255.255.0 gw 10.8.0.2
     367    Sun Feb  6 20:46:38 2005 Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:23 ET:0 EL:0 AF:3/1 ]
     368    Sun Feb  6 20:46:38 2005 UDPv4 link local (bound): [undef]:1194
     369    Sun Feb  6 20:46:38 2005 UDPv4 link remote: [undef]
     370    Sun Feb  6 20:46:38 2005 MULTI: multi_init called, r=256 v=256
     371    Sun Feb  6 20:46:38 2005 IFCONFIG POOL: base=10.8.0.4 size=62
     372    Sun Feb  6 20:46:38 2005 IFCONFIG POOL LIST
     373    Sun Feb  6 20:46:38 2005 Initialization Sequence Completed
     374
     375Starting the client
     376
     377As in the server configuration, it's best to initially start the OpenVPN server from the command line (or on Windows, by right-clicking on the client.ovpn file), rather than start it as a daemon or service:
     378
     379    openvpn [client config file]
     380
     381A normal client startup on Windows will look similar to the server output above, and should end with the Initialization Sequence Completed message.
     382
     383Now, try a ping across the VPN from the client. If you are using routing (i.e. dev tun in the server config file), try:
     384
     385    ping 10.8.0.1
     386
     387If you are using bridging (i.e. dev tap in the server config file), try to ping the IP address of a machine on the server's ethernet subnet.
     388
     389If the ping succeeds, congratulations! You now have a functioning VPN.
     390Troubleshooting
     391
     392If the ping failed or the OpenVPN client initialization failed to complete, here is a checklist of common symptoms and their solutions:
     393
     394    You get the error message: TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity). This error indicates that the client was unable to establish a network connection with the server.
     395
     396     
     397
     398    Solutions:
     399        Make sure the client is using the correct hostname/IP address and port number which will allow it to reach the OpenVPN server.
     400        If the OpenVPN server machine is a single-NIC box inside a protected LAN, make sure you are using a correct port forward rule on the server's gateway firewall. For example, suppose your OpenVPN box is at 192.168.4.4 inside the firewall, listening for client connections on UDP port 1194. The NAT gateway servicing the 192.168.4.x subnet should have a port forward rule that says forward UDP port 1194 from my public IP address to 192.168.4.4.
     401        Open up the server's firewall to allow incoming connections to UDP port 1194 (or whatever TCP/UDP port you have configured in the server config file).
     402    You get the error message: Initialization Sequence Completed with errors-- This error can occur on Windows if (a) You don't have the DHCP client service running, or (b) You are using certain third-party personal firewalls on XP SP2.
     403
     404     
     405
     406    Solution: Start the DHCP client server and make sure that you are using a personal firewall which is known to work correctly on XP SP2.
     407    You get the Initialization Sequence Completedmessage but the ping test fails -- This usually indicates that a firewall on either server or client is blocking VPN network traffic by filtering on the TUN/TAP interface.
     408
     409     
     410
     411    Solution: Disable the client firewall (if one exists) from filtering the TUN/TAP interface on the client. For example on Windows XP SP2, you can do this by going to Windows Security Center -> Windows Firewall -> Advanced and unchecking the box which corresponds to the TAP-Windows adapter (disabling the client firewall from filtering the TUN/TAP adapter is generally reasonable from a security perspective, as you are essentially telling the firewall not to block authenticated VPN traffic). Also make sure that the TUN/TAP interface on the server is not being filtered by a firewall (having said that, note that selective firewalling of the TUN/TAP interface on the server side can confer certain security benefits. See the access policies section below).
     412    The connection stalls on startup when using a proto udpconfiguration, the server log file shows this line:
     413
     414     
     415
     416        TLS: Initial packet from x.x.x.x:x, sid=xxxxxxxx xxxxxxxx
     417
     418    however the client log does not show an equivalent line.
     419
     420    Solution: You have a one-way connection from client to server. The server to client direction is blocked by a firewall, usually on the client side. The firewall can either be (a) a personal software firewall running on the client, or (b) the NAT router gateway for the client. Modify the firewall to allow returning UDP packets from the server to reach the client.
     421
     422See the FAQ for additional troubleshooting information.
     423Configuring OpenVPN to run automatically on system startup
     424
     425The lack of standards in this area means that most OSes have a different way of configuring daemons/services for autostart on boot. The best way to have this functionality configured by default is to install OpenVPN as a package, such as via RPM on Linux or using the Windows installer.
     426Linux
     427
     428If you install OpenVPN via an RPM or DEB package on Linux, the installer will set up an initscript. When executed, the initscript will scan for .conf configuration files in /etc/openvpn, and if found, will start up a separate OpenVPN daemon for each file.
     429Windows
     430
     431The Windows installer will set up a Service Wrapper, but leave it turned off by default. To activate it, go to Control Panel / Administrative Tools / Services, select the OpenVPN service, right-click on properties, and set the Startup Type to Automatic. This will configure the service for automatic start on the next reboot.
     432
     433When started, the OpenVPN Service Wrapper will scan the \Program Files\OpenVPN\config folder for .ovpn configuration files, starting a separate OpenVPN process on each file.
     434Controlling a running OpenVPN process
     435Running on Linux/BSD/Unix
     436
     437OpenVPN accepts several signals:
     438
     439    SIGUSR1 -- Conditional restart, designed to restart without root privileges
     440    SIGHUP -- Hard restart
     441    SIGUSR2 -- Output connection statistics to log file or syslog
     442    SIGTERM, SIGINT -- Exit
     443
     444Use the writepid directive to write the OpenVPN daemon's PID to a file, so that you know where to send the signal (if you are starting openvpn with an initscript, the script may already be passing a --writepid directive on the openvpn command line).
     445Running on Windows as a GUI
     446
     447See the OpenVPN GUI page.
     448Running in a Windows command prompt window
     449
     450On Windows, you can start OpenVPN by right clicking on an OpenVPN configuration file (.ovpn file) and selecting "Start OpenVPN on this config file".
     451
     452Once running in this fashion, several keyboard commands are available:
     453
     454    F1 -- Conditional restart (doesn't close/reopen TAP adapter)
     455    F2 -- Show connection statistics
     456    F3 -- Hard restart
     457    F4 -- Exit
     458
     459Running as a Windows Service
     460
     461When OpenVPN is started as a service on Windows, the only way to control it is:
     462
     463    Via the service control manager (Control Panel / Administrative Tools / Services) which gives start/stop control.
     464    Via the management interface (see below).
     465
     466Modifying a live server configuration
     467
     468While most configuration changes require you to restart the server, there are two directives in particular which refer to files which can be dynamically updated on-the-fly, and which will take immediate effect on the server without needing to restart the server process.
     469
     470client-config-dir -- This directive sets a client configuration directory, which the OpenVPN server will scan on every incoming connection, searching for a client-specific configuration file (see the the manual page for more information). Files in this directory can be updated on-the-fly, without restarting the server. Note that changes in this directory will only take effect for new connections, not existing connections. If you would like a client-specific configuration file change to take immediate effect on a currently connected client (or one which has disconnected, but where the server has not timed-out its instance object), kill the client instance object by using the management interface (described below). This will cause the client to reconnect and use the new client-config-dir file.
     471
     472crl-verify -- This directive names a Certificate Revocation List file, described below in the Revoking Certificates section. The CRL file can be modified on the fly, and changes will take effect immediately for new connections, or existing connections which are renegotiating their SSL/TLS channel (occurs once per hour by default). If you would like to kill a currently connected client whose certificate has just been added to the CRL, use the management interface (described below).
     473Status File
     474
     475The default server.conf file has a line
     476
     477    status openvpn-status.log
     478
     479which will output a list of current client connections to the file openvpn-status.log once per minute.
     480Using the management interface
     481
     482The OpenVPN management interface allows a great deal of control over a running OpenVPN process. You can use the management interface directly, by telneting to the management interface port, or indirectly by using an OpenVPN GUI which itself connects to the management interface.
     483
     484To enable the management interface on either an OpenVPN server or client, add this to the configuration file:
     485
     486    management localhost 7505
     487
     488This tells OpenVPN to listen on TCP port 7505 for management interface clients (port 7505 is an arbitrary choice -- you can use any free port).
     489
     490Once OpenVPN is running, you can connect to the management interface using a telnet client. For example:
     491
     492    ai:~ # telnet localhost 7505
     493    Trying 127.0.0.1...
     494    Connected to localhost.
     495    Escape character is '^]'.
     496    >INFO:OpenVPN Management Interface Version 1 -- type 'help' for more info
     497    help
     498    Management Interface for OpenVPN 2.0_rc14 i686-suse-linux [SSL] [LZO] [EPOLL] built on Feb 15 2005
     499    Commands:
     500    echo [on|off] [N|all]  : Like log, but only show messages in echo buffer.
     501    exit|quit              : Close management session.
     502    help                   : Print this message.
     503    hold [on|off|release]  : Set/show hold flag to on/off state, or
     504                             release current hold and start tunnel.
     505    kill cn                : Kill the client instance(s) having common name cn.
     506    kill IP:port           : Kill the client instance connecting from IP:port.
     507    log [on|off] [N|all]   : Turn on/off realtime log display
     508                             + show last N lines or 'all' for entire history.
     509    mute [n]               : Set log mute level to n, or show level if n is absent.
     510    net                    : (Windows only) Show network info and routing table.
     511    password type p        : Enter password p for a queried OpenVPN password.
     512    signal s               : Send signal s to daemon,
     513                             s = SIGHUP|SIGTERM|SIGUSR1|SIGUSR2.
     514    state [on|off] [N|all] : Like log, but show state history.
     515    status [n]             : Show current daemon status info using format #n.
     516    test n                 : Produce n lines of output for testing/debugging.
     517    username type u        : Enter username u for a queried OpenVPN username.
     518    verb [n]               : Set log verbosity level to n, or show if n is absent.
     519    version                : Show current version number.
     520    END
     521    exit
     522    Connection closed by foreign host.
     523    ai:~ #
     524
     525For more information, see the OpenVPN Management Interface Documentation.
     526Expanding the scope of the VPN to include additional machines on either the client or server subnet.
     527Including multiple machines on the server side when using a routed VPN (dev tun)
     528
     529Once the VPN is operational in a point-to-point capacity between client and server, it may be desirable to expand the scope of the VPN so that clients can reach multiple machines on the server network, rather than only the server machine itself.
     530
     531For the purpose of this example, we will assume that the server-side LAN uses a subnet of 10.66.0.0/24 and the VPN IP address pool uses 10.8.0.0/24 as cited in the server directive in the OpenVPN server configuration file.
     532
     533First, you must advertise the 10.66.0.0/24 subnet to VPN clients as being accessible through the VPN. This can easily be done with the following server-side config file directive:
     534
     535    push "route 10.66.0.0 255.255.255.0"
     536
     537Next, you must set up a route on the server-side LAN gateway to route the VPN client subnet (10.8.0.0/24) to the OpenVPN server (this is only necessary if the OpenVPN server and the LAN gateway are different machines).
     538
     539Make sure that you've enabled IP and TUN/TAP forwarding on the OpenVPN server machine.
     540Including multiple machines on the server side when using a bridged VPN (dev tap)
     541
     542One of the benefits of using ethernet bridging is that you get this for free without needing any additional configuration.
     543Including multiple machines on the client side when using a routed VPN (dev tun)
     544
     545In a typical road-warrior or remote access scenario, the client machine connects to the VPN as a single machine. But suppose the client machine is a gateway for a local LAN (such as a home office), and you would like each machine on the client LAN to be able to route through the VPN.
     546
     547For this example, we will assume that the client LAN is using the 192.168.4.0/24 subnet, and that the VPN client is using a certificate with a common name of client2. Our goal is to set up the VPN so that any machine on the client LAN can communicate with any machine on the server LAN through the VPN.
     548
     549Before setup, there are some basic prerequisites which must be followed:
     550
     551    The client LAN subnet (192.168.4.0/24 in our example) must not be exported to the VPN by the server or any other client sites which are using the same subnet. Every subnet which is joined to the VPN via routing must be unique.
     552    The client must have a unique Common Name in its certificate ("client2" in our example), and the duplicate-cn flag must not be used in the OpenVPN server configuration file.
     553
     554First, make sure that IP and TUN/TAP forwarding is enabled on the client machine.
     555
     556Next, we will deal with the necessary configuration changes on the server side. If the server configuration file does not currently reference a client configuration directory, add one now:
     557
     558    client-config-dir ccd
     559
     560In the above directive, ccd should be the name of a directory which has been pre-created in the default directory where the OpenVPN server daemon runs. On Linux this tends to be /etc/openvpn and on Windows it is usually \Program Files\OpenVPN\config. When a new client connects to the OpenVPN server, the daemon will check this directory for a file which matches the common name of the connecting client. If a matching file is found, it will be read and processed for additional configuration file directives to be applied to the named client.
     561
     562The next step is to create a file called client2 in the ccd directory. This file should contain the line:
     563
     564    iroute 192.168.4.0 255.255.255.0
     565
     566This will tell the OpenVPN server that the 192.168.4.0/24 subnet should be routed to client2.
     567
     568Next, add the following line to the main server config file (not the ccd/client2 file):
     569
     570    route 192.168.4.0 255.255.255.0
     571
     572Why the redundant route and iroute statements, you might ask? The reason is that route controls the routing from the kernel to the OpenVPN server (via the TUN interface) while iroute controls the routing from the OpenVPN server to the remote clients. Both are necessary.
     573
     574Next, ask yourself if you would like to allow network traffic between client2's subnet (192.168.4.0/24) and other clients of the OpenVPN server. If so, add the following to the server config file.
     575
     576    client-to-client
     577    push "route 192.168.4.0 255.255.255.0"
     578
     579This will cause the OpenVPN server to advertise client2's subnet to other connecting clients.
     580
     581The last step, and one that is often forgotten, is to add a route to the server's LAN gateway which directs 192.168.4.0/24 to the OpenVPN server box (you won't need this if the OpenVPN server box is the gateway for the server LAN). Suppose you were missing this step and you tried to ping a machine (not the OpenVPN server itself) on the server LAN from 192.168.4.8? The outgoing ping would probably reach the machine, but then it wouldn't know how to route the ping reply, because it would have no idea how to reach 192.168.4.0/24. The rule of thumb to use is that when routing entire LANs through the VPN (when the VPN server is not the same machine as the LAN gateway), make sure that the gateway for the LAN routes all VPN subnets to the VPN server machine.
     582
     583Similarly, if the client machine running OpenVPN is not also the gateway for the client LAN, then the gateway for the client LAN must have a route which directs all subnets which should be reachable through the VPN to the OpenVPN client machine.
     584Including multiple machines on the client side when using a bridged VPN (dev tap)
     585
     586This requires a more complex setup (maybe not more complex in practice, but more complicated to explain in detail):
     587
     588    You must bridge the client TAP interface with the LAN-connected NIC on the client.
     589    You must manually set the IP/netmask of the TAP interface on the client.
     590    You must configure client-side machines to use an IP/netmask that is inside of the bridged subnet, possibly by querying a DHCP server on the OpenVPN server side of the VPN.
     591
     592Pushing DHCP options to clients
     593
     594The OpenVPN server can push DHCP options such as DNS and WINS server addresses to clients (some caveats to be aware of). Windows clients can accept pushed DHCP options natively, while non-Windows clients can accept them by using a client-side up script which parses the foreign_option_n environmental variable list. See the man page or openvpn-users mailing list archive for non-Windows foreign_option_n documentation and script examples.
     595
     596For example, suppose you would like connecting clients to use an internal DNS server at 10.66.0.4 or 10.66.0.5 and a WINS server at 10.66.0.8. Add this to the OpenVPN server configuration:
     597
     598    push "dhcp-option DNS 10.66.0.4"
     599    push "dhcp-option DNS 10.66.0.5"
     600    push "dhcp-option WINS 10.66.0.8"
     601
     602To test this feature on Windows, run the following from a command prompt window after the machine has connected to an OpenVPN server:
     603
     604    ipconfig /all
     605
     606The entry for the TAP-Windows adapter should show the DHCP options which were pushed by the server.
     607Configuring client-specific rules and access policies
     608
     609Suppose we are setting up a company VPN, and we would like to establish separate access policies for 3 different classes of users:
     610
     611    System administrators -- full access to all machines on the network
     612    Employees -- access only to Samba/email server
     613    Contractors -- access to a special server only
     614
     615The basic approach we will take is (a) segregate each user class into its own virtual IP address range, and (b) control access to machines by setting up firewall rules which key off the client's virtual IP address.
     616
     617In our example, suppose that we have a variable number of employees, but only one system administrator, and two contractors. Our IP allocation approach will be to put all employees into an IP address pool, and then allocate fixed IP addresses for the system administrator and contractors.
     618
     619Note that one of the prerequisites of this example is that you have a software firewall running on the OpenVPN server machine which gives you the ability to define specific firewall rules. For our example, we will assume the firewall is Linux iptables.
     620
     621First, let's create a virtual IP address map according to user class:
     622Class   Virtual IP Range        Allowed LAN Access      Common Names
     623Employees       10.8.0.0/24     Samba/email server at 10.66.4.4         [variable]
     624System Administrators   10.8.1.0/24     Entire 10.66.4.0/24 subnet      sysadmin1
     625Contractors     10.8.2.0/24     Contractor server at 10.66.4.12         contractor1, contracter2
     626
     627Next, let's translate this map into an OpenVPN server configuration. First of all, make sure you've followed the steps above for making the 10.66.4.0/24 subnet available to all clients (while we will configure routing to allow client access to the entire 10.66.4.0/24 subnet, we will then impose access restrictions using firewall rules to implement the above policy table).
     628
     629First, define a static unit number for our tun interface, so that we will be able to refer to it later in our firewall rules:
     630
     631    dev tun0
     632
     633In the server configuration file, define the Employee IP address pool:
     634
     635    server 10.8.0.0 255.255.255.0
     636
     637Add routes for the System Administrator and Contractor IP ranges:
     638
     639    route 10.8.1.0 255.255.255.0
     640    route 10.8.2.0 255.255.255.0
     641
     642Because we will be assigning fixed IP addresses for specific System Administrators and Contractors, we will use a client configuration directory:
     643
     644    client-config-dir ccd
     645
     646Now place special configuration files in the ccd subdirectory to define the fixed IP address for each non-Employee VPN client.
     647ccd/sysadmin1
     648
     649    ifconfig-push 10.8.1.1 10.8.1.2
     650
     651ccd/contractor1
     652
     653    ifconfig-push 10.8.2.1 10.8.2.2
     654
     655ccd/contractor2
     656
     657    ifconfig-push 10.8.2.5 10.8.2.6
     658
     659Each pair of ifconfig-push addresses represent the virtual client and server IP endpoints. They must be taken from successive /30 subnets in order to be compatible with Windows clients and the TAP-Windows driver. Specifically, the last octet in the IP address of each endpoint pair must be taken from this set:
     660
     661    [  1,  2] [  5,  6] [  9, 10] [ 13, 14] [ 17, 18]
     662    [ 21, 22] [ 25, 26] [ 29, 30] [ 33, 34] [ 37, 38]
     663    [ 41, 42] [ 45, 46] [ 49, 50] [ 53, 54] [ 57, 58]
     664    [ 61, 62] [ 65, 66] [ 69, 70] [ 73, 74] [ 77, 78]
     665    [ 81, 82] [ 85, 86] [ 89, 90] [ 93, 94] [ 97, 98]
     666    [101,102] [105,106] [109,110] [113,114] [117,118]
     667    [121,122] [125,126] [129,130] [133,134] [137,138]
     668    [141,142] [145,146] [149,150] [153,154] [157,158]
     669    [161,162] [165,166] [169,170] [173,174] [177,178]
     670    [181,182] [185,186] [189,190] [193,194] [197,198]
     671    [201,202] [205,206] [209,210] [213,214] [217,218]
     672    [221,222] [225,226] [229,230] [233,234] [237,238]
     673    [241,242] [245,246] [249,250] [253,254]
     674
     675This completes the OpenVPN configuration. The final step is to add firewall rules to finalize the access policy. For this example, we will use firewall rules in the Linux iptables syntax:
     676
     677    # Employee rule
     678    iptables -A FORWARD -i tun0 -s 10.8.0.0/24 -d 10.66.4.4 -j ACCEPT
     679
     680    # Sysadmin rule
     681    iptables -A FORWARD -i tun0 -s 10.8.1.0/24 -d 10.66.4.0/24 -j ACCEPT
     682
     683    # Contractor rule
     684    iptables -A FORWARD -i tun0 -s 10.8.2.0/24 -d 10.66.4.12 -j ACCEPT
     685
     686Using alternative authentication methods
     687
     688OpenVPN 2.0 and later include a feature that allows the OpenVPN server to securely obtain a username and password from a connecting client, and to use that information as a basis for authenticating the client.
     689
     690To use this authentication method, first add the auth-user-pass directive to the client configuration. It will direct the OpenVPN client to query the user for a username/password, passing it on to the server over the secure TLS channel.
     691
     692Next, configure the server to use an authentication plugin, which may be a script, shared object, or DLL. The OpenVPN server will call the plugin every time a VPN client tries to connect, passing it the username/password entered on the client. The authentication plugin can control whether or not the OpenVPN server allows the client to connect by returning a failure (1) or success (0) value.
     693Using Script Plugins
     694
     695Script plugins can be used by adding the auth-user-pass-verify directive to the server-side configuration file. For example:
     696
     697    auth-user-pass-verify auth-pam.pl via-file
     698
     699will use the auth-pam.pl perl script to authenticate the username/password of connecting clients. See the description of auth-user-pass-verify in the manual page for more information.
     700
     701The auth-pam.pl script is included in the OpenVPN source file distribution in the sample-scripts subdirectory. It will authenticate users on a Linux server using a PAM authentication module, which could in turn implement shadow password, RADIUS, or LDAP authentication. auth-pam.pl is primarily intended for demonstration purposes. For real-world PAM authentication, use the openvpn-auth-pam shared object plugin described below.
     702Using Shared Object or DLL Plugins
     703
     704Shared object or DLL plugins are usually compiled C modules which are loaded by the OpenVPN server at run time. For example if you are using an RPM-based OpenVPN package on Linux, the openvpn-auth-pam plugin should be already built. To use it, add this to the server-side config file:
     705
     706    plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so login
     707
     708This will tell the OpenVPN server to validate the username/password entered by clients using the login PAM module.
     709
     710For real-world production use, it's better to use the openvpn-auth-pam plugin, because it has several advantages over the auth-pam.pl script:
     711
     712    The shared object openvpn-auth-pam plugin uses a split-privilege execution model for better security. This means that the OpenVPN server can run with reduced privileges by using the directives user nobody, group nobody, and chroot, and will still be able to authenticate against the root-readable-only shadow password file.
     713    OpenVPN can pass the username/password to a plugin via virtual memory, rather than via a file or the environment, which is better for local security on the server machine.
     714    C-compiled plugin modules generally run faster than scripts.
     715
     716If you would like more information on developing your own plugins for use with OpenVPN, see the README files in the plugin subdirectory of the OpenVPN source distribution.
     717
     718To build the openvpn-auth-pam plugin on Linux, cd to the plugin/auth-pam directory in the OpenVPN source distribution and run make.
     719Using username/password authentication as the only form of client authentication
     720
     721By default, using auth-user-pass-verify or a username/password-checking plugin on the server will enable dual authentication, requiring that both client-certificate and username/password authentication succeed in order for the client to be authenticated.
     722
     723While it is discouraged from a security perspective, it is also possible to disable the use of client certificates, and force username/password authentication only. On the server:
     724
     725    client-cert-not-required
     726
     727Such configurations should usually also set:
     728
     729    username-as-common-name
     730
     731which will tell the server to use the username for indexing purposes as it would use the Common Name of a client which was authenticating via a client certificate.
     732
     733Note that client-cert-not-required will not obviate the need for a server certificate, so a client connecting to a server which uses client-cert-not-required may remove the cert and key directives from the client configuration file, but not the ca directive, because it is necessary for the client to verify the server certificate.
     734How to add dual-factor authentication to an OpenVPN configuration using client-side smart cards
     735
     736Also see Article: The OpenVPN Smartcard HOWTO
     737
     738    About dual-factor authentication
     739    What is PKCS#11?
     740    Finding PKCS#11 provider library.
     741    How to configure a cryptographic token
     742    How to modify an OpenVPN configuration to make use of cryptographic tokens
     743        Determine the correct object.
     744        Using OpenVPN with PKCS#11.
     745        PKCS#11 implementation considerations.
     746        OpenSC PKCS#11 provider.
     747    Difference between PKCS#11 and Microsoft Cryptographic API (CryptoAPI).
     748
     749About dual-factor authentication
     750
     751Dual-factor authentication is a method of authentication that combines two elements: something you have and something you know.
     752
     753Something you have should be a device that cannot be duplicated; such a device can be a cryptographic token that contains a private secret key. This private key is generated inside the device and never leaves it. If a user possessing this token attempts to access protected services on a remote network, the authorization process which grants or denies network access can establish, with a high degree of certainty, that the user seeking access is in physical possession of a known, certified token.
     754
     755Something you know can be a password presented to the cryptographic device. Without presenting the proper password you cannot access the private secret key. Another feature of cryptographic devices is to prohibit the use of the private secret key if the wrong password had been presented more than an allowed number of times. This behavior ensures that if a user lost his device, it would be infeasible for another person to use it.
     756
     757Cryptographic devices are commonly called "smart cards" or "tokens", and are used in conjunction with a PKI (Public Key Infrastructure). The VPN server can examine a X.509 certificate and verify that the user holds the corresponding private secret key. Since the device cannot be duplicated and requires a valid password, the server is able to authenticate the user with a high degree of confidence.
     758
     759Dual-factor authentication is much stronger than password-based authentication, because in the worst-case scenario, only one person at a time can use the cryptographic token. Passwords can be guessed and can be exposed to other users, so in the worst-case scenario an infinite number of people could attempt to gain unauthorized access when resources are protected using password-only authentication.
     760
     761If you store the secret private key in a file, the key is usually encrypted by a password. The problem with this approach is that the encrypted key is exposed to decryption attacks or spyware/malware running on the client machine. Unlike when using a cryptographic device, the file cannot erase itself automatically after several failed decryption attempts.
     762What is PKCS#11?
     763
     764This standard specifies an API, called Cryptoki, to devices which hold cryptographic information and perform cryptographic functions. Cryptoki, pronounced "crypto-key" and short for cryptographic token interface, follows a simple object-based approach, addressing the goals of technology independence (any kind of device) and resource sharing (multiple applications accessing multiple devices), presenting to applications a common, logical view of the device called a cryptographic token.
     765
     766Source: RSA Security Inc. http://www.rsasecurity.com/rsalabs/pkcs/pkcs-11.
     767
     768To summarize, PKCS#11 is a standard that can be used by application software to access cryptographic tokens such as smart cards and other devices. Most device vendors provide a library that implements the PKCS#11 provider interface -- this library can be used by applications in order to access these devices. PKCS#11 is a cross-platform, vendor-independent free standard.
     769Finding PKCS#11 provider library
     770
     771The first thing you need to do is to find the provider library, it should be installed with the device drivers. Each vendor has its own library. For example, the OpenSC PKCS#11 provider is located at /usr/lib/pkcs11/opensc-pkcs11.so on Unix or at opensc-pkcs11.dll on Windows.
     772How to configure cryptographic token
     773
     774You should follow an enrollment procedure:
     775
     776    Initialize the PKCS#11 token.
     777    Generate RSA key pair on the PKCS#11 token.
     778    Create a certificate request based on the key pair, you can use OpenSC and OpenSSL in order to do that.
     779    Submit the certificate request to a certificate authority, and receive a certificate.
     780    Load the certificate onto the token, while noting that the id and label attributes of the certificate must match those of the private key.
     781
     782A configured token is a token that has a private key object and a certificate object, where both share the same id and label attributes.
     783
     784A simple enrollment utility is Easy-RSA 2.0 which is part of OpenVPN 2.1 series. Follow the instructions specified in the README file, and then use the pkitool in order to enroll.
     785
     786Initialize a token using the following command:
     787
     788    $ ./pkitool --pkcs11-slots /usr/lib/pkcs11/
     789    $ ./pkitool --pkcs11-init /usr/lib/pkcs11/ 
     790
     791Enroll a certificate using the following command:
     792
     793    $ ./pkitool --pkcs11 /usr/lib/pkcs11/   client1
     794
     795How to modify an OpenVPN configuration to make use of cryptographic tokens
     796
     797You should have OpenVPN 2.1 or above in order to use the PKCS#11 features.
     798Determine the correct object
     799
     800Each PKCS#11 provider can support multiple devices. In order to view the available object list you can use the following command:
     801
     802    $ openvpn --show-pkcs11-ids /usr/lib/pkcs11/
     803
     804    The following objects are available for use.
     805    Each object shown below may be used as parameter to
     806    --pkcs11-id option please remember to use single quote mark.
     807
     808    Certificate
     809           DN:             /CN=User1
     810           Serial:         490B82C4000000000075
     811           Serialized id:  aaaa/bbb/41545F5349474E415455524581D2A1A1B23C4AA4CB17FAF7A4600
     812
     813Each certificate/private key pair have unique "Serialized id" string. The serialized id string of the requested certificate should be specified to the pkcs11-id option using single quote marks.
     814
     815    pkcs11-id 'aaaa/bbb/41545F5349474E415455524581D2A1A1B23C4AA4CB17FAF7A4600'
     816
     817Using OpenVPN with PKCS#11
     818A typical set of OpenVPN options for PKCS#11
     819
     820    pkcs11-providers /usr/lib/pkcs11/
     821    pkcs11-id 'aaaa/bbb/41545F5349474E415455524581D2A1A1B23C4AA4CB17FAF7A4600'
     822
     823This will select the object which matches the pkcs11-id string.
     824Advanced OpenVPN options for PKCS#11
     825
     826    pkcs11-providers /usr/lib/pkcs11/provider1.so /usr/lib/pkcs11/provider2.so
     827    pkcs11-id 'aaaa/bbb/41545F5349474E415455524581D2A1A1B23C4AA4CB17FAF7A4600'
     828    pkcs11-pin-cache 300
     829    daemon
     830    auth-retry nointeract
     831    management-hold
     832    management-signal
     833    management 127.0.0.1 8888
     834    management-query-passwords
     835
     836This will load two providers into OpenVPN, use the certificate specified on pkcs11-id option, and use the management interface in order to query passwords. The daemon will resume into hold state on the event when token cannot be accessed. The token will be used for 300 seconds after which the password will be re-queried, session will disconnect if management session disconnects.
     837PKCS#11 implementation considerations
     838
     839Many PKCS#11 providers make use of threads, in order to avoid problems caused by implementation of LinuxThreads (setuid, chroot), it is highly recommend to upgrade to Native POSIX Thread Library (NPTL) enabled glibc if you intend to use PKCS#11.
     840OpenSC PKCS#11 provider
     841
     842OpenSC PKCS#11 provider is located at /usr/lib/pkcs11/opensc-pkcs11.so on Unix or at opensc-pkcs11.dll on Windows.
     843Difference between PKCS#11 and Microsoft Cryptographic API (CryptoAPI)
     844
     845PKCS#11 is a free, cross-platform vendor independent standard. CryptoAPI is a Microsoft specific API. Most smart card vendors provide support for both interfaces. In the Windows environment, the user should select which interface to use.
     846
     847The current implementation of OpenVPN that uses the MS CryptoAPI (cryptoapicert option) works well as long as you don't run OpenVPN as a service. If you wish to run OpenVPN in an administrative environment using a service, the implementation will not work with most smart cards because of the following reasons:
     848
     849    Most smart card providers do not load certificates into the local machine store, so the implementation will be unable to access the user certificate.
     850    If the OpenVPN client is running as a service without direct interaction with the end-user, the service cannot query the user to provide a password for the smart card, causing the password-verification process on the smart card to fail.
     851
     852Using the PKCS#11 interface, you can use smart cards with OpenVPN in any implementation, since PKCS#11 does not access Microsoft stores and does not necessarily require direct interaction with the end-user.
     853Routing all client traffic (including web-traffic) through the VPN
     854Overview
     855
     856By default, when an OpenVPN client is active, only network traffic to and from the OpenVPN server site will pass over the VPN. General web browsing, for example, will be accomplished with direct connections that bypass the VPN.
     857
     858In certain cases this behavior might not be desirable -- you might want a VPN client to tunnel all network traffic through the VPN, including general internet web browsing. While this type of VPN configuration will exact a performance penalty on the client, it gives the VPN administrator more control over security policies when a client is simultaneously connected to both the public internet and the VPN at the same time.
     859Implementation
     860
     861Add the following directive to the server configuration file:
     862
     863    push "redirect-gateway def1"
     864
     865If your VPN setup is over a wireless network, where all clients and the server are on the same wireless subnet, add the local flag:
     866
     867    push "redirect-gateway local def1"
     868
     869Pushing the redirect-gateway option to clients will cause all IP network traffic originating on client machines to pass through the OpenVPN server. The server will need to be configured to deal with this traffic somehow, such as by NATing it to the internet, or routing it through the server site's HTTP proxy.
     870
     871On Linux, you could use a command such as this to NAT the VPN client traffic to the internet:
     872
     873    iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
     874
     875This command assumes that the VPN subnet is 10.8.0.0/24 (taken from the server directive in the OpenVPN server configuration) and that the local ethernet interface is eth0.
     876
     877When redirect-gateway is used, OpenVPN clients will route DNS queries through the VPN, and the VPN server will need handle them. This can be accomplished by pushing a DNS server address to connecting clients which will replace their normal DNS server settings during the time that the VPN is active. For example:
     878
     879    push "dhcp-option DNS 10.8.0.1"
     880
     881will configure Windows clients (or non-Windows clients with some extra server-side scripting) to use 10.8.0.1 as their DNS server. Any address which is reachable from clients may be used as the DNS server address.
     882Caveats
     883
     884Redirecting all network traffic through the VPN is not entirely a problem-free proposition. Here are some typical gotchas to be aware of:
     885
     886    Many OpenVPN client machines connecting to the internet will periodically interact with a DHCP server to renew their IP address leases. The redirect-gateway option might prevent the client from reaching the local DHCP server (because DHCP messages would be routed over the VPN), causing it to lose its IP address lease.
     887    Issues exist with respect to pushing DNS addresses to Windows clients.
     888    Web browsing performance on the client will be noticably slower.
     889
     890For more information on the mechanics of the redirect-gateway directive, see the manual page.
     891Running an OpenVPN server on a dynamic IP address
     892
     893While OpenVPN clients can easily access the server via a dynamic IP address without any special configuration, things get more interesting when the server itself is on a dynamic address. While OpenVPN has no trouble handling the situation of a dynamic server, some extra configuration is required.
     894
     895The first step is to get a dynamic DNS address which can be configured to "follow" the server every time the server's IP address changes. There are several dynamic DNS service providers available, such as dyndns.org.
     896
     897The next step is to set up a mechanism so that every time the server's IP address changes, the dynamic DNS name will be quickly updated with the new IP address, allowing clients to find the server at its new IP address. There are two basic ways to accomplish this:
     898
     899    Use a NAT router appliance with dynamic DNS support (such as the Linksys BEFSR41). Most of the inexpensive NAT router appliances that are widely available have the capability to update a dynamic DNS name every time a new DHCP lease is obtained from the ISP. This setup is ideal when the OpenVPN server box is a single-NIC machine inside the firewall.
     900
     901     
     902    Use a dynamic DNS client application such as ddclient to update the dynamic DNS address whenever the server IP address changes. This setup is ideal when the machine running OpenVPN has multiple NICs and is acting as a site-wide firewall/gateway. To implement this setup, you need to set up a script to be run by your DHCP client software every time an IP address change occurs. This script should (a) run ddclientto notify your dynamic DNS provider of your new IP address and (b) restart the OpenVPN server daemon.
     903
     904     
     905
     906The OpenVPN client by default will sense when the server's IP address has changed, if the client configuration is using a remote directive which references a dynamic DNS name. The usual chain of events is that (a) the OpenVPN client fails to receive timely keepalive messages from the server's old IP address, triggering a restart, and (b) the restart causes the DNS name in the remote directive to be re-resolved, allowing the client to reconnect to the server at its new IP address.
     907
     908More information can be found in the FAQ.
     909Connecting to an OpenVPN server via an HTTP proxy.
     910
     911OpenVPN supports connections through an HTTP proxy, with the following authentication modes:
     912
     913    No proxy authentication
     914    Basic proxy authentication
     915    NTLM proxy authentication
     916
     917First of all, HTTP proxy usage requires that you use TCP as the tunnel carrier protocol. So add the following to both client and server configurations:
     918
     919    proto tcp
     920
     921Make sure that any proto udp lines in the config files are deleted.
     922
     923Next, add the http-proxy directive to the client configuration file (see the manual page for a full description of this directive).
     924
     925For example, suppose you have an HTTP proxy server on the client LAN at 192.168.4.1, which is listening for connections on port 1080. Add this to the client config:
     926
     927    http-proxy 192.168.4.1 1080
     928
     929Suppose the HTTP proxy requires Basic authentication:
     930
     931    http-proxy 192.168.4.1 1080 stdin basic
     932
     933Suppose the HTTP proxy requires NTLM authentication:
     934
     935    http-proxy 192.168.4.1 1080 stdin ntlm
     936
     937The two authentication examples above will cause OpenVPN to prompt for a username/password from standard input. If you would instead like to place these credentials in a file, replace stdin with a filename, and place the username on line 1 of this file and the password on line 2.
     938Connecting to a Samba share over OpenVPN
     939
     940This example is intended show how OpenVPN clients can connect to a Samba share over a routed dev tun tunnel. If you are ethernet bridging (dev tap), you probably don't need to follow these instructions, as OpenVPN clients should see server-side machines in their network neighborhood.
     941
     942For this example, we will assume that:
     943
     944    the server-side LAN uses a subnet of 10.66.0.0/24,
     945    the VPN IP address pool uses 10.8.0.0/24 (as cited in the server directive in the OpenVPN server configuration file),
     946    the Samba server has an IP address of 10.66.0.4, and
     947    the Samba server has already been configured and is reachable from the local LAN.
     948
     949If the Samba and OpenVPN servers are running on different machines, make sure you've followed the section on expanding the scope of the VPN to include additional machines.
     950
     951Next, edit your Samba configuration file (smb.conf). Make sure the hosts allow directive will permit OpenVPN clients coming from the 10.8.0.0/24 subnet to connect. For example:
     952
     953    hosts allow = 10.66.0.0/24 10.8.0.0/24 127.0.0.1
     954
     955If you are running the Samba and OpenVPN servers on the same machine, you may want to edit the interfaces directive in the smb.conf file to also listen on the TUN interface subnet of 10.8.0.0/24:
     956
     957    interfaces  = 10.66.0.0/24 10.8.0.0/24
     958
     959If you are running the Samba and OpenVPN servers on the same machine, connect from an OpenVPN client to a Samba share using the folder name:
     960
     961    \\10.8.0.1\\sharename
     962
     963If the Samba and OpenVPN servers are on different machines, use folder name:
     964
     965    \\10.66.0.4\sharename
     966
     967For example, from a command prompt window:
     968
     969    net use z: \\10.66.0.4\sharename /USER:myusername
     970
     971Implementing a load-balancing/failover configuration
     972Client
     973
     974The OpenVPN client configuration can refer to multiple servers for load balancing and failover. For example:
     975
     976    remote server1.mydomain
     977    remote server2.mydomain
     978    remote server3.mydomain
     979
     980will direct the OpenVPN client to attempt a connection with server1, server2, and server3 in that order. If an existing connection is broken, the OpenVPN client will retry the most recently connected server, and if that fails, will move on to the next server in the list. You can also direct the OpenVPN client to randomize its server list on startup, so that the client load will be probabilistically spread across the server pool.
     981
     982    remote-random
     983
     984If you would also like DNS resolution failures to cause the OpenVPN client to move to the next server in the list, add the following:
     985
     986    resolv-retry 60
     987
     988The 60 parameter tells the OpenVPN client to try resolving each remote DNS name for 60 seconds before moving on to the next server in the list.
     989
     990The server list can also refer to multiple OpenVPN server daemons running on the same machine, each listening for connections on a different port, for example:
     991
     992    remote smp-server1.mydomain 8000
     993    remote smp-server1.mydomain 8001
     994    remote smp-server2.mydomain 8000
     995    remote smp-server2.mydomain 8001
     996
     997If your servers are multi-processor machines, running multiple OpenVPN daemons on each server can be advantageous from a performance standpoint.
     998
     999OpenVPN also supports the remote directive referring to a DNS name which has multiple A records in the zone configuration for the domain. In this case, the OpenVPN client will randomly choose one of the A records every time the domain is resolved.
     1000Server
     1001
     1002The simplest approach to a load-balanced/failover configuration on the server is to use equivalent configuration files on each server in the cluster, except use a different virtual IP address pool for each server. For example:
     1003
     1004server1
     1005
     1006    server 10.8.0.0 255.255.255.0
     1007
     1008server2
     1009
     1010    server 10.8.1.0 255.255.255.0
     1011
     1012server3
     1013
     1014    server 10.8.2.0 255.255.255.0
     1015
     1016Hardening OpenVPN Security
     1017
     1018One of the often-repeated maxims of network security is that one should never place so much trust in a single security component that its failure causes a catastrophic security breach. OpenVPN provides several mechanisms to add additional security layers to hedge against such an outcome.
     1019tls-auth
     1020
     1021The tls-auth directive adds an additional HMAC signature to all SSL/TLS handshake packets for integrity verification. Any UDP packet not bearing the correct HMAC signature can be dropped without further processing. The tls-auth HMAC signature provides an additional level of security above and beyond that provided by SSL/TLS. It can protect against:
     1022
     1023    DoS attacks or port flooding on the OpenVPN UDP port.
     1024    Port scanning to determine which server UDP ports are in a listening state.
     1025    Buffer overflow vulnerabilities in the SSL/TLS implementation.
     1026    SSL/TLS handshake initiations from unauthorized machines (while such handshakes would ultimately fail to authenticate, tls-auth can cut them off at a much earlier point).
     1027
     1028Using tls-auth requires that you generate a shared-secret key that is used in addition to the standard RSA certificate/key:
     1029
     1030    openvpn --genkey --secret ta.key
     1031
     1032This command will generate an OpenVPN static key and write it to the file ta.key. This key should be copied over a pre-existing secure channel to the server and all client machines. It can be placed in the same directory as the RSA .key and .crt files.
     1033
     1034In the server configuration, add:
     1035
     1036    tls-auth ta.key 0
     1037
     1038In the client configuration, add:
     1039
     1040    tls-auth ta.key 1
     1041
     1042proto udp
     1043
     1044While OpenVPN allows either the TCP or UDP protocol to be used as the VPN carrier connection, the UDP protocol will provide better protection against DoS attacks and port scanning than TCP:
     1045
     1046    proto udp
     1047
     1048user/group (non-Windows only)
     1049
     1050OpenVPN has been very carefully designed to allow root privileges to be dropped after initialization, and this feature should always be used on Linux/BSD/Solaris. Without root privileges, a running OpenVPN server daemon provides a far less enticing target to an attacker.
     1051
     1052    user nobody
     1053    group nobody
     1054
     1055Unprivileged mode (Linux only)
     1056
     1057On Linux OpenVPN can be run completely unprivileged. This configuration is a little more complex, but provides best security.
     1058
     1059In order to work with this configuration, OpenVPN must be configured to use iproute interface, this is done by specifying --enable-iproute2 to configure script. sudo package should also be available on your system.
     1060
     1061This configuration uses the Linux ability to change the permission of a tun device, so that unprivileged user may access it. It also uses sudo in order to execute iproute so that interface properties and routing table may be modified.
     1062
     1063OpenVPN configuration:
     1064
     1065        Write the following script and place it at: /usr/local/sbin/unpriv-ip:
     1066
     1067    #!/bin/sh
     1068    sudo /sbin/ip $*
     1069
     1070        Execute visudo, and add the followings to allow user 'user1' to execute /sbin/ip:
     1071
     1072    user1 ALL=(ALL)  NOPASSWD: /sbin/ip
     1073
     1074        You can also enable a group of users with the following command:
     1075
     1076    %users ALL=(ALL)  NOPASSWD: /sbin/ip
     1077
     1078        Add the following to your OpenVPN configuration:
     1079
     1080    dev tunX/tapX
     1081    iproute /usr/local/sbin/unpriv-ip
     1082
     1083        Please note that you must select constant X and specify tun or tap not both.
     1084        As root add persistant interface, and permit user and/or group to manage it, the following create tunX (replace with your own) and allow user1 and group users to access it.
     1085
     1086    openvpn --mktun --dev tunX --type tun --user user1 --group users
     1087
     1088    Run OpenVPN in the context of the unprivileged user.
     1089
     1090Further security constraints may be added by examining the parameters at the /usr/local/sbin/unpriv-ip script.
     1091chroot (non-Windows only)
     1092
     1093The chroot directive allows you to lock the OpenVPN daemon into a so-called chroot jail, where the daemon would not be able to access any part of the host system's filesystem except for the specific directory given as a parameter to the directive. For example,
     1094
     1095    chroot jail
     1096
     1097would cause the OpenVPN daemon to cd into the jail subdirectory on initialization, and would then reorient its root filesystem to this directory so that it would be impossible thereafter for the daemon to access any files outside of jail and its subdirectory tree. This is important from a security perspective, because even if an attacker were able to compromise the server with a code insertion exploit, the exploit would be locked out of most of the server's filesystem.
     1098
     1099Caveats: because chroot reorients the filesystem (from the perspective of the daemon only), it is necessary to place any files which OpenVPN might need after initialization in the jail directory, such as:
     1100
     1101    the crl-verify file, or
     1102    the client-config-dir directory.
     1103
     1104Larger RSA keys
     1105
     1106The RSA key size is controlled by the KEY_SIZE variable in the easy-rsa/vars file, which must be set before any keys are generated. Currently set to 1024 by default, this value can reasonably be increased to 2048 with no negative impact on VPN tunnel performance, except for a slightly slower SSL/TLS renegotiation handshake which occurs once per client per hour, and a much slower one-time Diffie Hellman parameters generation process using the easy-rsa/build-dh script.
     1107Larger symmetric keys
     1108
     1109By default OpenVPN uses Blowfish, a 128 bit symmetrical cipher.
     1110
     1111OpenVPN automatically supports any cipher which is supported by the OpenSSL library, and as such can support ciphers which use large key sizes. For example, the 256-bit version of AES (Advanced Encryption Standard) can be used by adding the following to both server and client configuration files:
     1112
     1113    cipher AES-256-CBC
     1114
     1115Keep the root key (ca.key) on a standalone machine without a network connection
     1116
     1117One of the security benefits of using an X509 PKI (as OpenVPN does) is that the root CA key (ca.key) need not be present on the OpenVPN server machine. In a high security environment, you might want to specially designate a machine for key signing purposes, keep the machine well-protected physically, and disconnect it from all networks. Floppy disks can be used to move key files back and forth, as necessary. Such measures make it extremely difficult for an attacker to steal the root key, short of physical theft of the key signing machine.
     1118Revoking Certificates
     1119
     1120Revoking a certificate means to invalidate a previously signed certificate so that it can no longer be used for authentication purposes.
     1121
     1122Typical reasons for wanting to revoke a certificate include:
     1123
     1124    The private key associated with the certificate is compromised or stolen.
     1125    The user of an encrypted private key forgets the password on the key.
     1126    You want to terminate a VPN user's access.
     1127
     1128Example
     1129
     1130As an example, we will revoke the client2 certificate, which we generated above in the "key generation" section of the HOWTO.
     1131
     1132First open up a shell or command prompt window and cd to the easy-rsa directory as you did in the "key generation" section above. On Linux/BSD/Unix:
     1133
     1134    . ./vars
     1135    ./revoke-full client2
     1136
     1137On Windows:
     1138
     1139    vars
     1140    revoke-full client2
     1141
     1142You should see output similar to this:
     1143
     1144    Using configuration from /root/openvpn/20/openvpn/tmp/easy-rsa/openssl.cnf
     1145    DEBUG[load_index]: unique_subject = "yes"
     1146    Revoking Certificate 04.
     1147    Data Base Updated
     1148    Using configuration from /root/openvpn/20/openvpn/tmp/easy-rsa/openssl.cnf
     1149    DEBUG[load_index]: unique_subject = "yes"
     1150    client2.crt: /C=KG/ST=NA/O=OpenVPN-TEST/CN=client2/emailAddress=me@myhost.mydomain
     1151    error 23 at 0 depth lookup:certificate revoked
     1152
     1153Note the "error 23" in the last line. That is what you want to see, as it indicates that a certificate verification of the revoked certificate failed.
     1154
     1155The revoke-full script will generate a CRL (certificate revocation list) file called crl.pem in the keys subdirectory. The file should be copied to a directory where the OpenVPN server can access it, then CRL verification should be enabled in the server configuration:
     1156
     1157    crl-verify crl.pem
     1158
     1159Now all connecting clients will have their client certificates verified against the CRL, and any positive match will result in the connection being dropped.
     1160CRL Notes
     1161
     1162    When the crl-verify option is used in OpenVPN, the CRL file will be re-read any time a new client connects or an existing client renegotiates the SSL/TLS connection (by default once per hour). This means that you can update the CRL file while the OpenVPN server daemon is running, and have the new CRL take effect immediately for newly connecting clients. If the client whose certificate you are revoking is already connected, you can restart the server via a signal (SIGUSR1 or SIGHUP) and flush all clients, or you can telnet to the management interfaceand explicitly kill the specific client instance object on the server without disturbing other clients.
     1163
     1164     
     1165    While the crl-verify directive can be used on both the OpenVPN server and clients, it is generally unnecessary to distribute a CRL file to clients unless a server certificate has been revoked. Clients don't need to know about other client certificates which have been revoked because clients shouldn't be accepting direct connections from other clientsin the first place.
     1166
     1167     
     1168    The CRL file is not secret, and should be made world-readable so that the OpenVPN daemon can read it after root privileges have been dropped.
     1169
     1170     
     1171    If you are using the chrootdirective, make sure to put a copy of the CRL file in the chroot directory, since unlike most other files which OpenVPN reads, the CRL file will be read after the chroot call is executed, not before.
     1172
     1173     
     1174    A common reason why certificates need to be revoked is that the user encrypts their private key with a password, then forgets the password. By revoking the original certificate, it is possible to generate a new certificate/key pair with the user's original common name.
     1175
     1176     
     1177
     1178Important Note on possible "Man-in-the-Middle" attack if clients do not verify the certificate of the server they are connecting to.
     1179
     1180To avoid a possible Man-in-the-Middle attack where an authorized client tries to connect to another client by impersonating the server, make sure to enforce some kind of server certificate verification by clients. There are currently five different ways of accomplishing this, listed in the order of preference:
     1181
     1182    [OpenVPN 2.1 and above]Build your server certificates with specific key usage and extended key usage. The RFC3280 determine that the following attributes should be provided for TLS connections:
     1183
     1184     
     1185    Mode        Key usage       Extended key usage
     1186    Client      digitalSignature        TLS Web Client Authentication
     1187    keyAgreement
     1188    digitalSignature, keyAgreement
     1189    Server      digitalSignature, keyEncipherment       TLS Web Server Authentication
     1190    digitalSignature, keyAgreement
     1191
     1192    You can build your server certificates with the build-key-server script (see the easy-rsa documentation for more info). This will designate the certificate as a server-only certificate by setting the right attributes. Now add the following line to your client configuration:
     1193
     1194        remote-cert-tls server
     1195
     1196    [OpenVPN 2.0 and below] Build your server certificates with the build-key-server script (see the easy-rsa documentation for more info). This will designate the certificate as a server-only certificate by setting nsCertType=server. Now add the following line to your client configuration:
     1197
     1198     
     1199
     1200        ns-cert-type server
     1201
     1202    This will block clients from connecting to any server which lacks the nsCertType=server designation in its certificate, even if the certificate has been signed by the ca file in the OpenVPN configuration file.
     1203    Use the tls-remotedirective on the client to accept/reject the server connection based on the common name of the server certificate.
     1204
     1205     
     1206    Use a tls-verifyscript or plugin to accept/reject the server connection based on a custom test of the server certificate's embedded X509 subject details.
     1207
     1208     
     1209    Sign server certificates with one CA and client certificates with a different CA. The client configuration ca directive should reference the server-signing CA file, while the server configuration cadirective should reference the client-signing CA file.
     1210
     1211     
     1212
     1213Sample OpenVPN 2.0 configuration files
     1214
     1215sample-config-files/server.conf
     1216
     1217    #################################################
     1218    # Sample OpenVPN 2.0 config file for            #
     1219    # multi-client server.                          #
     1220    #                                               #
     1221    # This file is for the server side              #
     1222    # of a many-clients  one-server                 #
     1223    # OpenVPN configuration.                        #
     1224    #                                               #
     1225    # OpenVPN also supports                         #
     1226    # single-machine  single-machine                #
     1227    # configurations (See the Examples page         #
     1228    # on the web site for more info).               #
     1229    #                                               #
     1230    # This config should work on Windows            #
     1231    # or Linux/BSD systems.  Remember on            #
     1232    # Windows to quote pathnames and use            #
     1233    # double backslashes, e.g.:                     #
     1234    # "C:\\Program Files\\OpenVPN\\config\\foo.key" #
     1235    #                                               #
     1236    # Comments are preceded with '#' or ';'         #
     1237    #################################################
     1238
     1239    # Which local IP address should OpenVPN
     1240    # listen on? (optional)
     1241    ;local a.b.c.d
     1242
     1243    # Which TCP/UDP port should OpenVPN listen on?
     1244    # If you want to run multiple OpenVPN instances
     1245    # on the same machine, use a different port
     1246    # number for each one.  You will need to
     1247    # open up this port on your firewall.
     1248    port 1194
     1249
     1250    # TCP or UDP server?
     1251    ;proto tcp
     1252    proto udp
     1253
     1254    # "dev tun" will create a routed IP tunnel,
     1255    # "dev tap" will create an ethernet tunnel.
     1256    # Use "dev tap0" if you are ethernet bridging
     1257    # and have precreated a tap0 virtual interface
     1258    # and bridged it with your ethernet interface.
     1259    # If you want to control access policies
     1260    # over the VPN, you must create firewall
     1261    # rules for the the TUN/TAP interface.
     1262    # On non-Windows systems, you can give
     1263    # an explicit unit number, such as tun0.
     1264    # On Windows, use "dev-node" for this.
     1265    # On most systems, the VPN will not function
     1266    # unless you partially or fully disable
     1267    # the firewall for the TUN/TAP interface.
     1268    ;dev tap
     1269    dev tun
     1270
     1271    # Windows needs the TAP-Windows adapter name
     1272    # from the Network Connections panel if you
     1273    # have more than one.  On XP SP2 or higher,
     1274    # you may need to selectively disable the
     1275    # Windows firewall for the TAP adapter.
     1276    # Non-Windows systems usually don't need this.
     1277    ;dev-node MyTap
     1278
     1279    # SSL/TLS root certificate (ca), certificate
     1280    # (cert), and private key (key).  Each client
     1281    # and the server must have their own cert and
     1282    # key file.  The server and all clients will
     1283    # use the same ca file.
     1284    #
     1285    # See the "easy-rsa" directory for a series
     1286    # of scripts for generating RSA certificates
     1287    # and private keys.  Remember to use
     1288    # a unique Common Name for the server
     1289    # and each of the client certificates.
     1290    #
     1291    # Any X509 key management system can be used.
     1292    # OpenVPN can also use a PKCS #12 formatted key file
     1293    # (see "pkcs12" directive in man page).
     1294    ca ca.crt
     1295    cert server.crt
     1296    key server.key  # This file should be kept secret
     1297
     1298    # Diffie hellman parameters.
     1299    # Generate your own with:
     1300    #   openssl dhparam -out dh1024.pem 1024
     1301    # Substitute 2048 for 1024 if you are using
     1302    # 2048 bit keys.
     1303    dh dh1024.pem
     1304
     1305    # Configure server mode and supply a VPN subnet
     1306    # for OpenVPN to draw client addresses from.
     1307    # The server will take 10.8.0.1 for itself,
     1308    # the rest will be made available to clients.
     1309    # Each client will be able to reach the server
     1310    # on 10.8.0.1. Comment this line out if you are
     1311    # ethernet bridging. See the man page for more info.
     1312    server 10.8.0.0 255.255.255.0
     1313
     1314    # Maintain a record of client  virtual IP address
     1315    # associations in this file.  If OpenVPN goes down or
     1316    # is restarted, reconnecting clients can be assigned
     1317    # the same virtual IP address from the pool that was
     1318    # previously assigned.
     1319    ifconfig-pool-persist ipp.txt
     1320
     1321    # Configure server mode for ethernet bridging.
     1322    # You must first use your OS's bridging capability
     1323    # to bridge the TAP interface with the ethernet
     1324    # NIC interface.  Then you must manually set the
     1325    # IP/netmask on the bridge interface, here we
     1326    # assume 10.8.0.4/255.255.255.0.  Finally we
     1327    # must set aside an IP range in this subnet
     1328    # (start=10.8.0.50 end=10.8.0.100) to allocate
     1329    # to connecting clients.  Leave this line commented
     1330    # out unless you are ethernet bridging.
     1331    ;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
     1332
     1333    # Push routes to the client to allow it
     1334    # to reach other private subnets behind
     1335    # the server.  Remember that these
     1336    # private subnets will also need
     1337    # to know to route the OpenVPN client
     1338    # address pool (10.8.0.0/255.255.255.0)
     1339    # back to the OpenVPN server.
     1340    ;push "route 192.168.10.0 255.255.255.0"
     1341    ;push "route 192.168.20.0 255.255.255.0"
     1342
     1343    # To assign specific IP addresses to specific
     1344    # clients or if a connecting client has a private
     1345    # subnet behind it that should also have VPN access,
     1346    # use the subdirectory "ccd" for client-specific
     1347    # configuration files (see man page for more info).
     1348
     1349    # EXAMPLE: Suppose the client
     1350    # having the certificate common name "Thelonious"
     1351    # also has a small subnet behind his connecting
     1352    # machine, such as 192.168.40.128/255.255.255.248.
     1353    # First, uncomment out these lines:
     1354    ;client-config-dir ccd
     1355    ;route 192.168.40.128 255.255.255.248
     1356    # Then create a file ccd/Thelonious with this line:
     1357    #   iroute 192.168.40.128 255.255.255.248
     1358    # This will allow Thelonious' private subnet to
     1359    # access the VPN.  This example will only work
     1360    # if you are routing, not bridging, i.e. you are
     1361    # using "dev tun" and "server" directives.
     1362
     1363    # EXAMPLE: Suppose you want to give
     1364    # Thelonious a fixed VPN IP address of 10.9.0.1.
     1365    # First uncomment out these lines:
     1366    ;client-config-dir ccd
     1367    ;route 10.9.0.0 255.255.255.252
     1368    # Then add this line to ccd/Thelonious:
     1369    #   ifconfig-push 10.9.0.1 10.9.0.2
     1370
     1371    # Suppose that you want to enable different
     1372    # firewall access policies for different groups
     1373    # of clients.  There are two methods:
     1374    # (1) Run multiple OpenVPN daemons, one for each
     1375    #     group, and firewall the TUN/TAP interface
     1376    #     for each group/daemon appropriately.
     1377    # (2) (Advanced) Create a script to dynamically
     1378    #     modify the firewall in response to access
     1379    #     from different clients.  See man
     1380    #     page for more info on learn-address script.
     1381    ;learn-address ./script
     1382
     1383    # If enabled, this directive will configure
     1384    # all clients to redirect their default
     1385    # network gateway through the VPN, causing
     1386    # all IP traffic such as web browsing and
     1387    # and DNS lookups to go through the VPN
     1388    # (The OpenVPN server machine may need to NAT
     1389    # the TUN/TAP interface to the internet in
     1390    # order for this to work properly).
     1391    # CAVEAT: May break client's network config if
     1392    # client's local DHCP server packets get routed
     1393    # through the tunnel.  Solution: make sure
     1394    # client's local DHCP server is reachable via
     1395    # a more specific route than the default route
     1396    # of 0.0.0.0/0.0.0.0.
     1397    ;push "redirect-gateway"
     1398
     1399    # Certain Windows-specific network settings
     1400    # can be pushed to clients, such as DNS
     1401    # or WINS server addresses.  CAVEAT:
     1402    # http://openvpn.net/faq.html#dhcpcaveats
     1403    ;push "dhcp-option DNS 10.8.0.1"
     1404    ;push "dhcp-option WINS 10.8.0.1"
     1405
     1406    # Uncomment this directive to allow different
     1407    # clients to be able to "see" each other.
     1408    # By default, clients will only see the server.
     1409    # To force clients to only see the server, you
     1410    # will also need to appropriately firewall the
     1411    # server's TUN/TAP interface.
     1412    ;client-to-client
     1413
     1414    # Uncomment this directive if multiple clients
     1415    # might connect with the same certificate/key
     1416    # files or common names.  This is recommended
     1417    # only for testing purposes.  For production use,
     1418    # each client should have its own certificate/key
     1419    # pair.
     1420    #
     1421    # IF YOU HAVE NOT GENERATED INDIVIDUAL
     1422    # CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
     1423    # EACH HAVING ITS OWN UNIQUE "COMMON NAME",
     1424    # UNCOMMENT THIS LINE OUT.
     1425    ;duplicate-cn
     1426
     1427    # The keepalive directive causes ping-like
     1428    # messages to be sent back and forth over
     1429    # the link so that each side knows when
     1430    # the other side has gone down.
     1431    # Ping every 10 seconds, assume that remote
     1432    # peer is down if no ping received during
     1433    # a 120 second time period.
     1434    keepalive 10 120
     1435
     1436    # For extra security beyond that provided
     1437    # by SSL/TLS, create an "HMAC firewall"
     1438    # to help block DoS attacks and UDP port flooding.
     1439    #
     1440    # Generate with:
     1441    #   openvpn --genkey --secret ta.key
     1442    #
     1443    # The server and each client must have
     1444    # a copy of this key.
     1445    # The second parameter should be '0'
     1446    # on the server and '1' on the clients.
     1447    ;tls-auth ta.key 0 # This file is secret
     1448
     1449    # Select a cryptographic cipher.
     1450    # This config item must be copied to
     1451    # the client config file as well.
     1452    ;cipher BF-CBC        # Blowfish (default)
     1453    ;cipher AES-128-CBC   # AES
     1454    ;cipher DES-EDE3-CBC  # Triple-DES
     1455
     1456    # Enable compression on the VPN link.
     1457    # If you enable it here, you must also
     1458    # enable it in the client config file.
     1459    comp-lzo
     1460
     1461    # The maximum number of concurrently connected
     1462    # clients we want to allow.
     1463    ;max-clients 100
     1464
     1465    # It's a good idea to reduce the OpenVPN
     1466    # daemon's privileges after initialization.
     1467    #
     1468    # You can uncomment this out on
     1469    # non-Windows systems.
     1470    ;user nobody
     1471    ;group nobody
     1472
     1473    # The persist options will try to avoid
     1474    # accessing certain resources on restart
     1475    # that may no longer be accessible because
     1476    # of the privilege downgrade.
     1477    persist-key
     1478    persist-tun
     1479
     1480    # Output a short status file showing
     1481    # current connections, truncated
     1482    # and rewritten every minute.
     1483    status openvpn-status.log
     1484
     1485    # By default, log messages will go to the syslog (or
     1486    # on Windows, if running as a service, they will go to
     1487    # the "\Program Files\OpenVPN\log" directory).
     1488    # Use log or log-append to override this default.
     1489    # "log" will truncate the log file on OpenVPN startup,
     1490    # while "log-append" will append to it.  Use one
     1491    # or the other (but not both).
     1492    ;log         openvpn.log
     1493    ;log-append  openvpn.log
     1494
     1495    # Set the appropriate level of log
     1496    # file verbosity.
     1497    #
     1498    # 0 is silent, except for fatal errors
     1499    # 4 is reasonable for general usage
     1500    # 5 and 6 can help to debug connection problems
     1501    # 9 is extremely verbose
     1502    verb 3
     1503
     1504    # Silence repeating messages.  At most 20
     1505    # sequential messages of the same message
     1506    # category will be output to the log.
     1507    ;mute 20
     1508
     1509sample-config-files/client.conf
     1510
     1511    ##############################################
     1512    # Sample client-side OpenVPN 2.0 config file #
     1513    # for connecting to multi-client server.     #
     1514    #                                            #
     1515    # This configuration can be used by multiple #
     1516    # clients, however each client should have   #
     1517    # its own cert and key files.                #
     1518    #                                            #
     1519    # On Windows, you might want to rename this  #
     1520    # file so it has a .ovpn extension           #
     1521    ##############################################
     1522
     1523    # Specify that we are a client and that we
     1524    # will be pulling certain config file directives
     1525    # from the server.
     1526    client
     1527
     1528    # Use the same setting as you are using on
     1529    # the server.
     1530    # On most systems, the VPN will not function
     1531    # unless you partially or fully disable
     1532    # the firewall for the TUN/TAP interface.
     1533    ;dev tap
     1534    dev tun
     1535
     1536    # Windows needs the TAP-Windows adapter name
     1537    # from the Network Connections panel
     1538    # if you have more than one.  On XP SP2,
     1539    # you may need to disable the firewall
     1540    # for the TAP adapter.
     1541    ;dev-node MyTap
     1542
     1543    # Are we connecting to a TCP or
     1544    # UDP server?  Use the same setting as
     1545    # on the server.
     1546    ;proto tcp
     1547    proto udp
     1548
     1549    # The hostname/IP and port of the server.
     1550    # You can have multiple remote entries
     1551    # to load balance between the servers.
     1552    remote my-server-1 1194
     1553    ;remote my-server-2 1194
     1554
     1555    # Choose a random host from the remote
     1556    # list for load-balancing.  Otherwise
     1557    # try hosts in the order specified.
     1558    ;remote-random
     1559
     1560    # Keep trying indefinitely to resolve the
     1561    # host name of the OpenVPN server.  Very useful
     1562    # on machines which are not permanently connected
     1563    # to the internet such as laptops.
     1564    resolv-retry infinite
     1565
     1566    # Most clients don't need to bind to
     1567    # a specific local port number.
     1568    nobind
     1569
     1570    # Downgrade privileges after initialization (non-Windows only)
     1571    ;user nobody
     1572    ;group nobody
     1573
     1574    # Try to preserve some state across restarts.
     1575    persist-key
     1576    persist-tun
     1577
     1578    # If you are connecting through an
     1579    # HTTP proxy to reach the actual OpenVPN
     1580    # server, put the proxy server/IP and
     1581    # port number here.  See the man page
     1582    # if your proxy server requires
     1583    # authentication.
     1584    ;http-proxy-retry # retry on connection failures
     1585    ;http-proxy [proxy server] [proxy port #]
     1586
     1587    # Wireless networks often produce a lot
     1588    # of duplicate packets.  Set this flag
     1589    # to silence duplicate packet warnings.
     1590    ;mute-replay-warnings
     1591
     1592    # SSL/TLS parms.
     1593    # See the server config file for more
     1594    # description.  It's best to use
     1595    # a separate .crt/.key file pair
     1596    # for each client.  A single ca
     1597    # file can be used for all clients.
     1598    ca ca.crt
     1599    cert client.crt
     1600    key client.key
     1601
     1602    # Verify server certificate by checking
     1603    # that the certicate has the nsCertType
     1604    # field set to "server".  This is an
     1605    # important precaution to protect against
     1606    # a potential attack discussed here:
     1607    #  http://openvpn.net/howto.html#mitm
     1608    #
     1609    # To use this feature, you will need to generate
     1610    # your server certificates with the nsCertType
     1611    # field set to "server".  The build-key-server
     1612    # script in the easy-rsa folder will do this.
     1613    ;ns-cert-type server
     1614
     1615    # If a tls-auth key is used on the server
     1616    # then every client must also have the key.
     1617    ;tls-auth ta.key 1
     1618
     1619    # Select a cryptographic cipher.
     1620    # If the cipher option is used on the server
     1621    # then you must also specify it here.
     1622    ;cipher x
     1623
     1624    # Enable compression on the VPN link.
     1625    # Don't enable this unless it is also
     1626    # enabled in the server config file.
     1627    comp-lzo
     1628
     1629    # Set log file verbosity.
     1630    verb 3
     1631
     1632    # Silence repeating messages
     1633    ;mute 20
     1634
     1635        Try our new VPN Service https://www.privatetunnel.com
     1636
     1637Copyright © 2002-2013 by OpenVPN Technologies, Inc. < info@openvpn.net>. OpenVPN is a trademark of OpenVPN Technologies, Inc.