Encrypted communication between client and server will occur over UDP port 1194, the default OpenVPN port. Generate a static key: $ openvpn -genkey -secret static.key Copy the static key to both client and server, over a pre-existing secure channel. Server configuration file dev tun ifconfig 10.8.0.1 10.8.0.2 secret static.key. Jul 22, 2016 In another post I cover setting up and OpenVPN server on a Tomato powered router and making client connections to that server. In setting up a new phone, I see the OpenVPN for Android app will now import yourVPNclient.ovpn files (much easier than transferring and importing the separate key and cert components as covered in my prior post).

Mar 12, 2016  Replace the data between the 'BEGIN' and 'END' lines with the real data from your own files. You don't have to use TLS-AUTH, but it provides one more layer of protection. Easy Windows Guide. This page contains a no-frills guide to getting OpenVPN up and running on a Windows server and client(s). For a more detailed understanding of setting up OpenVPN and its advanced features, see the HOWTO page.

Translation(s): English - Français - Русский - Polski

Contents

  1. Configuration
    1. Test VPN
  2. Application to a VPN passing through a http proxy

OpenVPN is an SSL/TLS VPN solution. It is able to traverse NAT connections and firewalls. This page explains briefly how to configure a VPN with OpenVPN, from both server-side and client-side.

Openvpn Generate Static Key File

Install the openvpn package on both client and server.

To enable OpenVPN in the Gnome NetworkManager applet for the taskbar notification area, the additional package network-manager-openvpn-gnome has to be installed:

OpenVPN can authenticate users via user/pass, pre-shared key, certificates, etc.

Test VPN

Openvpn generate static key file download

Test a raw connection.

server test

From a server shell, run

if your client has a static IP#; otherwise, run

You should see console output resembling

While openvpn is running, check your network configuration with sudo ifconfig -a. Output should include

Note that, if you kill openvpn (e.g., with Control-c in its console), you will not see the above network interface.

client test

You may also test with ping.

Static-Key VPN

In the server's /etc/openvpn directory, run the following command to generate a static key:

Copy this static key to the clients /etc/openvpn directory using a secure channel like scp or sftp.

On the server, create a new /etc/openvpn/tun0.conf file and add the following:

Where 10.9.8.x is your VPN subnetwork, 10.9.8.1 will be IP of the server, 10.9.8.2 is IP of client.

On the client, copy /etc/openvpn/static.key from server and create a new /etc/openvpn/tun0.conf file and add the following:

On the server's firewall, open up UDP 1194 (default port).

If you are using ?shorewall, on both devices, add a new VPN zone to represent tun0 and create a default policy for it. This means adding something to the following files in /etc/shorewall:

  • zone
  • interfaces
  • policy

Bear in mind that 90% of all connection problems encountered by new OpenVPN users are firewall-related.

Start OpenVPN by hand on both sides with the following command:

You should probably configure your route at this step.

Generate A Static Openvpn Key

To verify that the VPN is running, you should be able to ping 10.9.8.2 from the server and 10.9.8.1 from the client.

TLS-enabled VPN

In server, copy key generating script from openvpn example to /etc/openvpn and add executable permission:

In Jessie and above easy-rsa is a separate package. So you'll have to install that in addition to openvpn.

On Wheezy:

On Jessie and above:

Openvpn Key File

Edit /etc/openvpn/easy-rsa/vars bottom according to your organization.

Execute the following command:

Create a symbolic link of the OpenSSL config file with the correct version, so it can be used by the commands of Easy-RSA. In Debian Stretch, it can be done by executing the following command:

Remember:

  • only .key files should be kept confidential.
  • .crt and .csr files can be sent over insecure channels such as plaintext email.
  • do not need to copy a .key file between computers.
  • each computer will have its own certificate/key pair.

Generate CERTIFICATE AUTHORITY (CA) CERTIFICATE/KEY:

It will generate ca.crt and ca.key in /etc/openvpn/easy-rsa/keys/ directory.

Generate BUILD AN INTERMEDIATE CERTIFICATE AUTHORITY CERTIFICATE/KEY (optional):

It will generate server.crt and server.key in /etc/openvpn/easy-rsa/keys/, and signed with your root certificate.

Generate BUILD DIFFIE-HELLMAN PARAMETERS (necessary for the server end of a SSL/TLS connection):

Generate key for each client: Use one of the two (build-key or build-key-pass). You'll be asked for 'Enter PEM pass phrase', this is the passphrase you'll need to login at the client.

Generate key with password (this protect the key and request the password every time that you connect to the server), for each client:

It will generate keys in /etc/openvpn/easy-rsa/keys/

Copy the ca.crt, clientname.crt, clientname.key from Server to Client/etc/openvpn/easy-rsa/keys/ directory.

Check OpenVPN RSA Key and code.mixpanel.com VPN for details.

Test the connectivity from command line.

Server:

Client:

If the connection is successful create file configuration.

In Server create /etc/openvpn/server.conf as follows:

Check code.mixpanel.com VPN and rackspace OpenVPN for details.

Create log directory:

Restart OpenVPN.

Note that the /etc/init.d/openvpn script will start an openvpn server for every .conf file in /etc/openvpn/, so if you still have the tun0.conf file from above, rename it to something else than *.conf. In the case of systemd only one openvpn server is started by default.

In Client create /etc/openvpn/client.conf as follows:

(note: you may use graphical vpn tool network-manager UI by providing the key and certificates)

Restart OpenVPN:

Debian Server with Android / iOS devices

OpenVPN can be configured to use with Android / iOS devices.

In Debian Server, create required certificates if you have a fresh installation of ?OpenVpn:

Modify below lines in /etc/openvpn/server.conf:

8.8.8.8 is Google DNS server. You may change to your preferred DNS server.

Test that the configuration works:

If it does, Ctrl-C out of this and restart OpenVPN server to use the new configuration:

Or on systems using systemd:

Create client profile file /etc/openvpn/client.ovpn and attach certificates to it:

Modify below lines in client profile file /etc/openvpn/client.ovpn:

where ?YourServerIp and ?YourServerPort should be changed to your server. Three lines (#ca, #cert, #key) are remarked as the required certificates were attached to the profile file instead of individual files.

e-mail or upload the client configuration file /etc/openvpn/client.ovpn to google drive in order to download to iPhone.

For iOS devices, install OpenVPN Connect client. Then transfer the client configuration file /etc/openvpn/client.ovpn to the device by e-mail or by Google Drive. Open the configuration file in Mail apps or Google Drive apps.

For Android devices, install OpenVPN Connect client. Then copy the client configuration file /etc/openvpn/client.ovpn to the storage of the device. Open the configuration file in OpenVPN apps.

You'll also want to run the server parts of the 'Forward traffic via VPN' steps below. Your phone OpenVPN client should take care of the client parts automatically.

In Server enable runtime IP forwarding:

Edit /etc/sysctl.conf uncomment the following line to make it permanent:

Execute the following command in server for testing:

You may also use the rc.firewall-iptables script from TLDP Masquerade as an alternative.

In client:

If you use graphical client generally you may not need to execute these command.

If everying is working fine, save the iptables rules:

To restore:

add this to startup script. Debian wiki iptables page for details.

By default, all configured VPNs are started during system boot. Edit /etc/default/openvpn to start specific VPNs or to disable this behavior. Systemd users may need to run systemctl daemon-reload once to enable new VPNs.

Openvpn Generate Static Key File Converter

openvpn ifupdown hooks are also available for starting/stopping tunnels using /etc/network/interfaces, e.g.:

See /usr/share/doc/openvpn/README.Debian.gz for more information.

To automatically start a VPN located in /etc/openvpn/client/ or /etc/openvpn/server/, enable openvpn-client@<name>.service or openvpn-server@<name>.service. For instance, a client configuration located in /etc/openvpn/client/vpn0.conf would be automatically started by enabling openvpn-client@vpn0.service.

This part describe how to configure a VPN to pass through a http proxy, which allow only trafic on port 443 (and 80). This use the http_proxy of OpenVPN.

  1. First of all, check that the port 443 isn't already used by another service on your server.
  2. Configure OpenVPN on server side by adding port 443 and proto tcp-server to the configuration file.

  3. Configure OpenVPN on the client side by adding port 443, proto tcp-client and http-proxy 1.1.1.1 8080 to the configuration file.

Where 1.1.1.1 and 8080 are IP and port of your proxy.

  1. Now you should launch OpenVPN on the server and next on the client.
  2. At this time, you should configure routes to use the VPN tunnel:
    • Remove the default route through the proxy: route del default eth0

    • Add default route through your VPN: route add default gw 10.9.8.1 dev tun0

    • You should keep the route to the proxy with: route add 1.1.1.1 eth0

Update your /etc/resolv.conf according to your needs.

TODO

  1. Explain how to enable the management interface (http://openvpn.net/index.php/open-source/documentation/miscellaneous/79-management-interface.html)

  • OpenVPN home-page

  • code.mixpanel.com VPN

  • rackspace OpenVPN

  • openvpn pki how to

  • RSA key Management OpenVPN

  • OpnVPN Howto

  • Ubuntu OpenVPN

  • TLDP Masquerade

  • Other VPN clients

Permalink

Join GitHub today

GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.

Sign up
Branch:master
Find file Copy path
Fetching contributors…
# Edit this file, and save to a .ovpn extension
# so that OpenVPN will activate it when run
# as a service.
# Change 'myremote' to be your remote host,
# or comment out to enter a listening
# server mode.
remote myremote
# Uncomment this line to use a different
# port number than the default of 1194.
; port 1194
# Choose one of three protocols supported by
# OpenVPN. If left commented out, defaults
# to udp.
; proto [tcp-server tcp-client udp]
# You must specify one of two possible network
# protocols, 'dev tap' or 'dev tun' to be used
# on both sides of the connection. 'tap' creates
# a VPN using the ethernet protocol while 'tun'
# uses the IP protocol. You must use 'tap'
# if you are ethernet bridging or want to route
# broadcasts. 'tun' is somewhat more efficient
# but requires configuration of client software
# to not depend on broadcasts. Some platforms
# such as Solaris, OpenBSD, and Mac OS X only
# support 'tun' interfaces, so if you are
# connecting to such a platform, you must also
# use a 'tun' interface on the Windows side.
# Enable 'dev tap' or 'dev tun' but not both!
dev tap
# This is a 'dev tap' ifconfig that creates
# a virtual ethernet subnet.
# 10.3.0.1 is the local VPN IP address
# and 255.255.255.0 is the VPN subnet.
# Only define this option for 'dev tap'.
ifconfig 10.3.0.1 255.255.255.0
# This is a 'dev tun' ifconfig that creates
# a point-to-point IP link.
# 10.3.0.1 is the local VPN IP address and
# 10.3.0.2 is the remote VPN IP address.
# Only define this option for 'dev tun'.
# Make sure to include the 'tun-mtu' option
# on the remote machine, but swap the order
# of the ifconfig addresses.
;tun-mtu 1500
;ifconfig 10.3.0.1 10.3.0.2
# If you have fragmentation issues or misconfigured
# routers in the path which block Path MTU discovery,
# lower the TCP MSS and internally fragment non-TCP
# protocols.
;fragment 1300
;mssfix
# If you have set up more than one TAP-Win32 adapter
# on your system, you must refer to it by name.
;dev-node my-tap
# You can generate a static OpenVPN key
# by selecting the Generate Key option
# in the start menu.
#
# You can also generate key.txt manually
# with the following command:
# openvpn --genkey secret key.txt
#
# key must match on both ends of the connection,
# so you should generate it on one machine and
# copy it to the other over a secure medium.
# Place key.txt in the same directory as this
# config file.
secret key.txt
# Uncomment this section for a more reliable
# detection when a system loses its connection.
# For example, dial-ups or laptops that travel
# to other locations.
#
# If this section is enabled and 'myremote'
# above is a dynamic DNS name (i.e. dyndns.org),
# OpenVPN will dynamically 'follow' the IP
# address of 'myremote' if it changes.
; ping-restart 60
; ping-timer-rem
; persist-tun
; persist-key
; resolv-retry 86400
# keep-alive ping
ping 10
# enable LZO compression
comp-lzo
# moderate verbosity
verb 4
mute 10
  • Copy lines
  • Copy permalink