OpenVPN 2
Updated: 12/30/2007
General Information
This guide will help you set up OpenVPN to allow remote users to securely connect to the internal LAN or use the VPN tunnel as an endpoint when on insecure wireless access points, allowing safe transmission of data without worries of being sniffed or intercepted.Requirements
You will need the following items to be able to complete this guide:Installation
We only have one thing to compile.|
# # |
cd /usr/ports/security/openvpn make install clean |
Server Configuration
First thing's first, we need a directory to store the configuration files and keys, so let's create that directory structure|
# # # # # |
cd /usr/local/etc/ mkdir openvpn cd openvpn mkdir easy-rsa mkdir cert |
|
# # |
cd /usr/local/etc/openvpn/easy-rsa cp -r /usr/local/share/doc/openvpn/easy-rsa/2.0/ . |
|
export EASY_RSA="`pwd`" export KEY_CONFIG="$EASY_RSA/openssl.cnf" export KEY_DIR="/usr/local/etc/openvpn/cert" # Issue rm -rf warning echo NOTE: If you run ./clean-all, I will be doing a rm -rf on $KEY_DIR export KEY_SIZE=2048 export CA_EXPIRE=3650 export KEY_EXPIRE=3650 export KEY_COUNTRY="US" export KEY_PROVINCE="NY" export KEY_CITY="New York" export KEY_ORG="OrgName" export KEY_EMAIL="email@example.net" |
| # | bash |
| # | . ./vars |
|
# # # |
bash build-ca bash build-key-server server bash build-dh |
|
;local a.b.c.d port 1194 ;proto tcp proto udp dev tun ca cert/ca.crt cert cert/server.crt key cert/server.key # This file should be kept secret dh cert/dh2048.pem server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt ;push "route 192.168.20.0 255.255.255.0" push "redirect-gateway" push "dhcp-option DNS 4.2.2.2" ;push "dhcp-option WINS 10.8.0.1" keepalive 10 120 # For extra security beyond that provided # by SSL/TLS, create an "HMAC firewall" # to help block DoS attacks and UDP port flooding. # # Generate with: # openvpn --genkey --secret ta.key # # The server and each client must have # a copy of this key. # The second parameter should be 0 # on the server and 1 on the clients. tls-auth ta.key 0 # This file is secret comp-lzo max-clients 20 user nobody group nobody persist-key persist-tun status openvpn-status.log verb 3 mute 10 |
| # | echo 'openvpn_enable="YES"' >> /etc/rc.conf |
| # | /usr/local/etc/rc.d/openvpn start |
|
vpn_if="tun0" nat on $ext_if from 10.8.0.0/24 to any -> ($ext_if) pass in quick proto udp from any to port 1194 keep state label "openvpn" # Pass stuff on the VPN interface pass quick on $vpn_if keep state |
Client Configuration
On the client we need to generate a private key, as well as a certificate signing request, or CSR. Create a new directory .openvpn to hold all the files. When OpenSSL asks you for the Organization name, you need to fill in the same value as you used to create the server key, which was also set as KEY_ORG in the vars file. When it requests a common name, use your full name, or a derivation thereof, all common names have to be unique, and if yours is not you will not be allowed to connect to the OpenVPN server.|
# # # |
mkdir ~/.openvpn cd ~/.openvpn openssl req -days 3650 -new -keyout openvpn.key -out openvpn.csr |
| # | bash |
|
# # |
cd /usr/local/etc/openvpn/easy-rsa/ . ./vars |
| # | bash sign-req ../cert/example |
|
client dev tun proto udp remote [IP address or hostname] 1194 resolv-retry infinite nobind persist-key persist-tun ca [homedir]/.openvpn/ca.crt cert [homedir]/.openvpn/openvpn.crt key [homedir]/.openvpn/openvpn.key ns-cert-type server tls-auth [homedir]/.openvpn/ta.key 1 comp-lzo verb 3 mute 10 |
| # | openvpn --config [homedir]/.openvpn/client.conf |
This guide is © 2007 - 2008 Jan-Willem Regeer.
Author: Jan-Willem Regeer
bsdguides at x-istence dot com