Jump to content
M2G

Run OpenVPN on Windows, Mac and Linux/Unix

Recommended Posts

Posted (edited)

We'll get you past the daunting configuration issues so you can use OpenVPN to provide no-cost, secure networking for your Windows, Mac or Unix/Linux systems.

OpenVPN is famously difficult to get up and running, but the truth is that it needn’t be. In this second and concluding OpenVPN article I am going to go through what it takes to get an OpenVPN Ethernet tunnel set up between a laptop computer and an office or home machine acting as an OpenVPN server.

Downloading and Installing OpenVPN

Before you can get OpenVPN running on any computer you need to download and install it:

Creating a Public Key Infrastructure

Once you’ve got OpenVPN successfully installed, it’s time to build the public key infrastructure needed for certificate-based authentication. If you don’t know what this means, don’t worry: just follow the instructions. A fuller explanation can be found at HOWTO

To get started, you’ll need to use the Easy-RSA PKI suite.

On Windows machines you’ll find it at: C:Program FilesOpenVPNeasy-rsa

On Linux machines this will probably be installed in an easy-rsa directory machines at /usr/share/doc/packages/opevpn or /usr/share/doc/openvpn-2.0, but it’s a good idea to move this to /etc/openvpn to prevent it getting overwritten by future updates.

Generating the Master Certificate Authority (CA) Certificate & Key

Windows: From the Start button select cmd, and in the command window type:

cd "C:Program FilesOpenVPNeasy-rsa

Linux/BSD/UNIX: Open a terminal window and type:

cd /etc/openvpn/easy-rsa

(assuming you have moved the easy-rsa directory to this location)

Then type the following commands, followed by return:

Windows:

init-config
vars
clean-all
build-ca

Linux/BSD/UNIX:

./init-config
./vars
./clean-all
./build-ca

The last command will invoke a window which will ask for a series of values. You can press the return key to enter the default values for all of these except the value for Common Name. For this, type: TestVPN

Generating the Server and Client Certificates and Keys

openvpn2_1.jpg

Then next step is to generate a server certificate and key, again using the Easy-RSA suite. The command for this is:

Windows:

 build-key-server server

Linux/BSD/UNIX:

./build-key-server server

In the interactive session that follows, simply press Enter to provide the default value each time, until you are asked for a Common Name. For Common Name enter “server” , then continue entering the default values until prompted to sign the certificate. Answer “y” to this question and to the following one to finish.

Then generate the certificate and key for your client machine. The process is similar to the one for building the server certificate and key, but this time enter client1 as the common name.

If you think you may want to access the OpenVPN server from more than one laptop, repeat the process, replacing client2 or client3 for client1 each time.

Windows:

 build-key client1

Linux/BSD/UNIX:

 ./build-key client1

Generating Diffie-Hellman Parameters

The final step is to generate Diffie-Hellman parameters for key exchange:

Windows:

build-dh

Linux/BSD/UNIX:

./build-dh

You’ll find the results of all this work in a subfolder called keys in the easy-rsa folder, and the final task is to move the client key and certificate to your client device. The files in question are client1.key and client1.crt. (If you have created more than one client certificate key and certificate, move the client2.key and client2.crt files to the second machine, and so on.)

Windows: place the files in

C:WindowsProgram FilesOpenVPNeasy-rsakeys

Linux/BSD/Unix:

 place the files in /etc/openvpn/

openvpn2_2.jpg

Your public key infrastructure is now set up.

Creating the OpenVPN Configuration Files

When OpenVPN runs it reads a configuration file at c:Program FilesOpenVPNconfig (Windows) or in /etc/openvpn (Linux/BSD/Unix). This text file contains all the information OpenVPN needs to know to make or receive a connection, so it’s crucial that these files are correct.

The easiest way to get OpenVPN working in the way we want is to edit the highlighted lines in the following config files to match your network setup, save them as a text file and copy them to the appropriate location.

Server configuration file:

#server config file start
local 192.168.1.15 # Change this address to the IP address of the network card attached to your router. To ensure this does not change you need either to have a static local IP address, or to configure your router to always assign this local IP address to your server.

port 1194 # This is the port OpenVPN will run on. Change it to a different port if you prefer

proto udp

mssfix 1400

push "dhcp-option DNS XXX.XXX.XXX.XXX" # Replace the Xs with the IP address of the DNS server for your network

push "dhcp-option DNS YYY.YYY.YYY.YYY" # Replace the Xs with the IP address of the secondary DNS server for your network

dev tap

ca "C:\Program Files\OpenVPN\easy-rsa\keys\ca.crt" #change this location to /etc/openvpn (without quotation marks) for Linux/BSD/Unix systems

cert "C:\Program Files\OpenVPN\easy-rsa\keys\server.crt" #change this location to /etc/openvpn for Linux/BSD/Unix systems

key "C:\Program Files\OpenVPN\easy-rsa\keys\server.key" #change this location to /etc/openvpn for Linux/BSD/Unix systems

dh "C:\Program Files\OpenVPN\easy-rsa\keys\dh1024.pem" #change this location to /etc/openvpn for Linux/BSD/Unix systems

server 192.168.10.0 255.255.255.128 # This will be the virtual IP address and subnet of the server’s OpenVPN connection. Change it to something similar like 192.168.11.0 if this subnet is already in use

ifconfig-pool-persist ipp.txt
push "redirect-gateway def1"
keepalive 10 120
cipher BF-CBC # Blowfish (default)If you prefer, you can use one of the two ciphers listed below (which must be the same as the client)

#cipher AES-128-CBC # AES
#cipher DES-EDE3-CBC # Triple-DES
comp-lzo
max-clients 3 # Change the 3 to the number of client keys you have created
persist-key
persist-tun
status openvpn-status.log
# user nobody # remove the # at the start of the line for Linux/BSD/Unix systems
# group nobody # remove the first # at the start of the line for Linux/BSD/Unix systems

verb 1

#config file ends

Save this file as server.ovpn, and move it to c:Program FilesOpenVPNconfig (Windows) or /etc/openvpn (Linux/BSD/Unix)

What to Do If You Don’t Have a Static Public IP Address

OpenVPN clients connect to the OpenVPN server using a public IP address or host name that needs to be entered into the client config file. If your ISP provides your business or home network with a dynamic IP address that changes each time an Internet connection is reset then your client config will no longer work after a reconnection. To get round this you can get a free hostname from DynDNS which automatically points to your dynamic IP address, even when it changes. To get a dynamic host name (such as myhost.dyndns.org) visit Managed DNS | Outsourced DNS | Anycast DNS.

Client Configuration File

#client  config file start
client
dev tap
proto udp
remote XXX.XXX.X.XXX 1194 #Change the Xs to the static public IP address of your home or office network. If you do not have a static IP enter you dyndns name (like yourhost.dyndns.org) here. If you changed the port from 1194 to another port number in the server config change the 1194 here to the appropriate port number

route 192.168.1.0 255.255.255.0 vpn_gateway 3 #Change this to the IP address scheme and subnet of the local network your server is on.

resolv-retry infinite
nobind
persist-key
persist-tun
ca "C:\Program Files\OpenVPN\easy-rsa\keys\ca.crt" #change this to “/etc/openvpn/ca.crt” on Linux/BSD/Unix systems

cert "C:\Program Files\OpenVPN\easy-rsa\keys\client1.crt" # change this to “/etc/openvpn/client1.crt” on Linux/BSD/Unix systems key

key "C:\Program Files\OpenVPN\easy-rsa\keys\client1.key" # change this to “/etc/openvpn/client1.key” on Linux/BSD/Unix systems. This key file should be kept secret

ns-cert-type server
cipher BF-CBC # Blowfish (default)If you prefer, you can use one of the two ciphers listed below

#cipher AES-128-CBC # AES
#cipher DES-EDE3-CBC # Triple-DES
comp-lzo
verb 1
# user nobody # remove the first # at the start of the line for Linux/BSD/Unix systems
# group nobody # remove the first # at the start of the line for Linux/BSD/Unix systems
# end of client config file

Save this configuration file as a text file called client1.ovpn, and save it to c:Program FilesOpenVPNconfig (Windows) or /etc/openvpn (Linux/BSD/Unix) on your client device

Setting Up the Router

There are a couple of configuration changes that need to be made to the router connected to your server in order for OpenVPN to work properly.

Port Forwarding

Port forwarding ensures that any traffic sent to your router from the Internet on port 1194 (or the port that OpenVPN is configured to use in the configuration files) is forwarded to the local IP address of your server machine. To ensure this does not change you need either to configure the server machine to have a static local IP address, or to configure the DHCP server in your router to always assign the same local IP address to your server.

To configure port forwarding, log on to your router’s configuration page, find the option for port forwarding, and enter the following information:

  • Name: OpenVPN
  • Protocol: UDP
  • Starting Port: 1194 (change this as necessary)
  • End Port: 1194 (change this as necessary)

Forward to: 192.168.1.15 (change this to the local IP address of your OpenVPN server)

You’ll also the following routing information on your router’s “routing” or “advanced routing” page, to ensure that data can travel between the OpenVPN link and other devices on your home or office network:

  • Route name: OpenVPN
  • Destination LAN IP: 192.168.10.1 (change this to the virtual IP address specified in the server configuration file)
  • Subnet Mask: 255.255.255.252
  • Default Gateway: 192.168.1.15 (change this to the IP address of your home computer)

Running OpenVPN

To run OpenVPN, you need to start OpenVPN first on the server, and then on the client. Remember that the client machine needs to be connected to a different network.

  • Starting the server using Windows: Start OpenVPN GUI, then right click on the program’s icon in the system tray, select “server” and then “connect”.
  • Starting the server using OS X: From the Tunnelblick OpenVPN GUI select Connect “server”
  • Starting the server using Linux/BSD/Unix: Start a terminal window, then as root (or using sudo) type: openvpn –-config /etc/openvpn/server.ovpn

openvpn2_3.jpg

Repeat the process on the client machine, replacing “client1” for “server”

Testing OpenVPN

To confirm OpenVPN is working, try pinging another device connected to your LAN using its LAN IP address.

You can also open a browser on your client machine, and check your IP address by visiting a site like What's My IP Address? Networking Tools & More If OpenVPN is working correctly the IP address of your server, not your client machine, will be shown.

openvpn2_4.jpg

Sursa

Edited by M2G
  • Upvote 1
Posted

Foarte frumos! Chiar aveam nevoie.

Te-a? ruga totu?i s? dai un Edit Post » Go Advanced » Disable emoticons (ceva de genul, e în josul paginii) pentru ca textul s? fie mai u?or de citit.

Posted
Foarte frumos! Chiar aveam nevoie.

Te-a? ruga totu?i s? dai un Edit Post » Go Advanced » Disable emoticons (ceva de genul, e în josul paginii) pentru ca textul s? fie mai u?or de citit.

Done. Multumesc de atentionare.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...