M2G Posted June 14, 2012 Report Posted June 14, 2012 (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 OpenVPNBefore you can get OpenVPN running on any computer you need to download and install it:Windows: Download the OpenVPN GUI installation package from OpenVPN GUI for WindowsRed Hat, Fedora, CentOS: Download RPM packages from Index of /openvpnUbuntu: Download and install OpenVPN using Synaptic Package ManagerMac OS X: Download and install Tunnelblick OpenVPN GUI client installation package from tunnelblick - OpenVPN GUI for Mac OS X - Google Project HostingSource code: Download source code from Downloads, compile and install it.Creating a Public Key InfrastructureOnce 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 HOWTOTo get started, you’ll need to use the Easy-RSA PKI suite.On Windows machines you’ll find it at: C:Program FilesOpenVPNeasy-rsaOn 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 & KeyWindows: From the Start button select cmd, and in the command window type:cd "C:Program FilesOpenVPNeasy-rsaLinux/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-configvarsclean-allbuild-caLinux/BSD/UNIX:./init-config./vars./clean-all./build-caThe 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: TestVPNGenerating the Server and Client Certificates and KeysThen 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 serverLinux/BSD/UNIX: ./build-key-server serverIn 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 client1Linux/BSD/UNIX: ./build-key client1Generating Diffie-Hellman ParametersThe final step is to generate Diffie-Hellman parameters for key exchange:Windows:build-dhLinux/BSD/UNIX: ./build-dhYou’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-rsakeysLinux/BSD/Unix: place the files in /etc/openvpn/Your public key infrastructure is now set up.Creating the OpenVPN Configuration FilesWhen 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 startlocal 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 preferproto udpmssfix 1400push "dhcp-option DNS XXX.XXX.XXX.XXX" # Replace the Xs with the IP address of the DNS server for your networkpush "dhcp-option DNS YYY.YYY.YYY.YYY" # Replace the Xs with the IP address of the secondary DNS server for your networkdev tapca "C:\Program Files\OpenVPN\easy-rsa\keys\ca.crt" #change this location to /etc/openvpn (without quotation marks) for Linux/BSD/Unix systemscert "C:\Program Files\OpenVPN\easy-rsa\keys\server.crt" #change this location to /etc/openvpn for Linux/BSD/Unix systemskey "C:\Program Files\OpenVPN\easy-rsa\keys\server.key" #change this location to /etc/openvpn for Linux/BSD/Unix systemsdh "C:\Program Files\OpenVPN\easy-rsa\keys\dh1024.pem" #change this location to /etc/openvpn for Linux/BSD/Unix systemsserver 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 useifconfig-pool-persist ipp.txtpush "redirect-gateway def1" keepalive 10 120cipher 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-DEScomp-lzomax-clients 3 # Change the 3 to the number of client keys you have createdpersist-keypersist-tunstatus 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 systemsverb 1 #config file endsSave 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 AddressOpenVPN 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 startclientdev tapproto udpremote 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 numberroute 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 infinitenobindpersist-keypersist-tunca "C:\Program Files\OpenVPN\easy-rsa\keys\ca.crt" #change this to “/etc/openvpn/ca.crt” on Linux/BSD/Unix systemscert "C:\Program Files\OpenVPN\easy-rsa\keys\client1.crt" # change this to “/etc/openvpn/client1.crt” on Linux/BSD/Unix systems keykey "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 secretns-cert-type servercipher 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-DEScomp-lzoverb 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 fileSave 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 deviceSetting Up the RouterThere 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 ForwardingPort 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: OpenVPNProtocol: UDPStarting 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: OpenVPNDestination LAN IP: 192.168.10.1 (change this to the virtual IP address specified in the server configuration file)Subnet Mask: 255.255.255.252Default Gateway: 192.168.1.15 (change this to the IP address of your home computer)Running OpenVPNTo 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.ovpnRepeat the process on the client machine, replacing “client1” for “server”Testing OpenVPNTo 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.Sursa Edited June 14, 2012 by M2G 1 Quote
bcman Posted June 14, 2012 Report Posted June 14, 2012 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. Quote
M2G Posted June 14, 2012 Author Report Posted June 14, 2012 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. Quote