Search:  
Gentoo Wiki

HOWTO_OpenVPN_RoadWarrior


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

What's that?

IpSec is surely the most secure implementation for VPN connection, and it's mostly indicated for permanent VPN connections, but it's extremly difficult to configure and presents many problems when the connection passes through natting firewall. Due to the extreme difficulty in setting up a server, IpSEC based, for roadwarrior connection, this howto could help you to reach your scope with another simple tool. Take a look to OpenVPN.

Topology

MARS network is reachable from internet through the OpenVPN service installed on its firewall. Roadwarrior directly connected to internet through a modem, or natted through a firewall, could reach the MARS private network through a VPN.

Image:openvpnroadwarriortopology.png

Setup

Kernel Configuration

Linux Kernel Configuration: TUN/TAP device
Device Drivers  --->
  Network device support  --->
    <M>   Universal TUN/TAP device driver support

After recompilation, reboot your system and load the kernel module using modprobe:

# modprobe tun

Verify everything works correctly with:

# lsmod | grep tun

Add the module to /etc/modules.autoload.d/kernel-2.6:

File: /etc/modules.autoload.d/kernel-2.6
 ...
 tun

Service Installation

Modify your /etc/make.conf adding these USE Flag:

File: /etc/make.conf
 ...
 USE="... ssl"
 ...

Install the package:

# emerge -DNauv openvpn

Service Setup

OpenVPN, has advised in original documentation, works sharing the Certification Authority between server and clients. For this reason clients and server must possess of a common CA to validate the certificates: this is the first cause of security loss.

If someone would be able to get an access to the client, he could, thanks to the ca, build up a certificate and access the vpn through it.

(Note: The above statement is incorrect, as long as you dont give the client the ca.key file, which is not needed, a signiture from the CA can not be generated. See Talk Page --Xarses 00:38, 10 May 2007 (UTC))

The solution consists in generating two CA: one for the server and one for all the other clients. The configuration file of the server will point to the client CA, while the configuration file of the clients will point to the server one. In this way the CA on clients could not generate client certificates, cause the CA needed is only on the server.

To realize this solution you can create two different variable files:

File: /usr/share/openvpn/easy-rsa/vars
 export EASY_RSA="`pwd`"
 export KEY_CONFIG="$EASY_RSA/openssl.cnf"
 export KEY_DIR="$EASY_RSA/keys"
 echo NOTE: If you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
 export KEY_SIZE=1024
 export CA_EXPIRE=3650
 export KEY_EXPIRE=3650
 export KEY_COUNTRY="US"
 export KEY_PROVINCE="CA"
 export KEY_CITY="SanFrancisco"
 export KEY_ORG="Fort-Funston"
 export KEY_EMAIL="me@myhost.mydomain"
 


File: /usr/share/openvpn/easy-rsa/vars-client
 export EASY_RSA="`pwd`"
 export KEY_CONFIG="$EASY_RSA/openssl.cnf"
 export KEY_DIR="$EASY_RSA/keys-client"
 echo NOTE: If you run ./clean-all, I will be doing a rm -rf on $KEY_DIR
 export KEY_SIZE=1024
 export CA_EXPIRE=3650
 export KEY_EXPIRE=3650
 export KEY_COUNTRY="US"
 export KEY_PROVINCE="CA"
 export KEY_CITY="SanFrancisco"
 export KEY_ORG="Fort-Funston"
 export KEY_EMAIL="me@myhost.mydomain"
 


Load first the server variables file and create the CA:

cd /usr/share/openvpn/easy-rsa/
source ./vars
./clean-all
./build-ca

Generate server certificate:

./build-key-server server

Generate Diffie Hellman parameters:

./build-dh

Load the client variables file and create the CA:

cd /usr/share/openvpn/easy-rsa/
source ./vars-client
./clean-all
./build-ca

Generate certificates for clients:

./build-key-pass USERNAME1
./build-key-pass USERNAME2

see also SCRIPT section

Create the SSL certificate for cripted comunication:

cd /etc/openvpn/HOSTNAME
openvpn --genkey --secret ta.key

To revoke certificates use:

. ./vars
./revoke-full USERNAME

Service Configuration

Modify /etc/openvpn/HOSTNAME/local.conf

File: /etc/openvpn/HOSTNAME/local.conf
 # Which local IP address should OpenVPN
 # listen on? (optional)
 ;local a.b.c.d
 local YOUR_IP
 
 # Which TCP/UDP port should OpenVPN listen on?
 # If you want to run multiple OpenVPN instances
 # on the same machine, use a different port
 # number for each one.  You will need to
 # open up this port on your firewall.
 port 1194
 
 # TCP or UDP server?
 ;proto tcp
 proto udp
 
 # "dev tun" will create a routed IP tunnel,
 # "dev tap" will create an ethernet tunnel.
 # Use "dev tap" if you are ethernet bridging.
 # If you want to control access policies
 # over the VPN, you must create firewall
 # rules for the the TUN/TAP interface.
 # On non-Windows systems, you can give
 # an explicit unit number, such as tun0.
 # On Windows, use "dev-node" for this.
 # On most systems, the VPN will not function
 # unless you partially or fully disable
 # the firewall for the TUN/TAP interface.
 ;dev tap
 dev tun
 
 # Windows needs the TAP-Win32 adapter name
 # from the Network Connections panel if you
 # have more than one.  On XP SP2 or higher,
 # you may need to selectively disable the
 # Windows firewall for the TAP adapter.
 # Non-Windows systems usually don't need this.
 ;dev-node MyTap
 
 # SSL/TLS root certificate (ca), certificate
 # (cert), and private key (key).  Each client
 # and the server must have their own cert and
 # key file.  The server and all clients will
 # use the same ca file.
 #
 # See the "easy-rsa" directory for a series
 # of scripts for generating RSA certificates
 # and private keys.  Remember to use
 # a unique Common Name for the server
 # and each of the client certificates.
 #
 # Any X509 key management system can be used.
 # OpenVPN can also use a PKCS #12 formatted key file
 # (see "pkcs12" directive in man page).
 ca /usr/share/openvpn/easy-rsa/keys-client/ca.crt
 cert /usr/share/openvpn/easy-rsa/keys/server.crt
 key /usr/share/openvpn/easy-rsa/keys/server.key  # This file should be kept secret
 
 # Diffie hellman parameters.
 # Generate your own with:
 #   openssl dhparam -out dh1024.pem 1024
 # Substitute 2048 for 1024 if you are using
 # 2048 bit keys.
 dh /usr/share/openvpn/easy-rsa/keys/dh1024.pem
 
 # Configure server mode and supply a VPN subnet
 # for OpenVPN to draw client addresses from.
 # The server will take 10.8.0.1 for itself,
 # the rest will be made available to clients.
 # Each client will be able to reach the server
 # on 10.8.0.1. Comment this line out if you are
 # ethernet bridging. See the man page for more info.
 ;server 10.8.0.0 255.255.255.0
 server YOUR_NETWORK_OPENVPN 255.255.255.0 # for example 192.168.139.0
 
 # Maintain a record of client <-> virtual IP address
 # associations in this file.  If OpenVPN goes down or
 # is restarted, reconnecting clients can be assigned
 # the same virtual IP address from the pool that was
 # previously assigned.
 ifconfig-pool-persist ipp.txt
 
 # Configure server mode for ethernet bridging.
 # You must first use your OS's bridging capability
 # to bridge the TAP interface with the ethernet
 # NIC interface.  Then you must manually set the
 # IP/netmask on the bridge interface, here we
 # assume 10.8.0.4/255.255.255.0.  Finally we
 # must set aside an IP range in this subnet
 # (start=10.8.0.50 end=10.8.0.100) to allocate
 # to connecting clients.  Leave this line commented
 # out unless you are ethernet bridging.
 ;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100 
 
 # Push routes to the client to allow it
 # to reach other private subnets behind
 # the server.  Remember that these
 # private subnets will also need
 # to know to route the OpenVPN client
 # address pool (10.8.0.0/255.255.255.0)
 # back to the OpenVPN server.
 push "route YOUR_PRIVATE_NETWORK 255.255.255.0" # for example 192.168.143.0
 ;push "route 192.168.20.0 255.255.255.0"
 
 # To assign specific IP addresses to specific
 # clients or if a connecting client has a private
 # subnet behind it that should also have VPN access,
 # use the subdirectory "ccd" for client-specific
 # configuration files (see man page for more info).
 
 # EXAMPLE: Suppose the client
 # having the certificate common name "Thelonious"
 # also has a small subnet behind his connecting
 # machine, such as 192.168.40.128/255.255.255.248.
 # First, uncomment out these lines:
 ;client-config-dir ccd
 ;route 192.168.40.128 255.255.255.248
 # Then create a file ccd/Thelonious with this line:
 #   iroute 192.168.40.128 255.255.255.248
 # This will allow Thelonious' private subnet to
 # access the VPN.  This example will only work
 # if you are routing, not bridging, i.e. you are
 # using "dev tun" and "server" directives.
 
 # EXAMPLE: Suppose you want to give
 # Thelonious a fixed VPN IP address of 10.9.0.1.
 # First uncomment out these lines:
 ;client-config-dir ccd
 ;route 10.9.0.0 255.255.255.252
 # Then add this line to ccd/Thelonious:
 #   ifconfig-push 10.9.0.1 10.9.0.2
 
 # Our up script will establish routes
 # once the VPN is alive.
 up /etc/openvpn/HOSTNAME/firewall.up
 down /etc/openvpn/HOSTNAME/firewall.down
 
 # Suppose that you want to enable different
 # firewall access policies for different groups
 # of clients.  There are two methods:
 # (1) Run multiple OpenVPN daemons, one for each
 #     group, and firewall the TUN/TAP interface
 #     for each group/daemon appropriately.
 # (2) (Advanced) Create a script to dynamically
 #     modify the firewall in response to access
 #     from different clients.  See man
 #     page for more info on learn-address script.
 ;learn-address ./script 
 
 # If enabled, this directive will configure
 # all clients to redirect their default
 # network gateway through the VPN, causing
 # all IP traffic such as web browsing and
 # and DNS lookups to go through the VPN
 # (The OpenVPN server machine may need to NAT
 # the TUN/TAP interface to the internet in
 # order for this to work properly).
 # CAVEAT: May break client's network config if
 # client's local DHCP server packets get routed
 # through the tunnel.  Solution: make sure
 # client's local DHCP server is reachable via
 # a more specific route than the default route
 # of 0.0.0.0/0.0.0.0.
 ;push "redirect-gateway"
 
 # Certain Windows-specific network settings
 # can be pushed to clients, such as DNS
 # or WINS server addresses.  CAVEAT:
 # http://openvpn.net/faq.html#dhcpcaveats
 ;push "dhcp-option DNS 10.8.0.1"
 ;push "dhcp-option WINS 10.8.0.1"
 push "dhcp-option DNS YOUR_DNS_SERVER" # for example 192.168.143.1
 
 # Uncomment this directive to allow different
 # clients to be able to "see" each other.
 # By default, clients will only see the server.
 # To force clients to only see the server, you
 # will also need to appropriately firewall the
 # server's TUN/TAP interface.
 ;client-to-client 
 
 # Uncomment this directive if multiple clients
 # might connect with the same certificate/key
 # files or common names.  This is recommended
 # only for testing purposes.  For production use,
 # each client should have its own certificate/key
 # pair.
 #
 # IF YOU HAVE NOT GENERATED INDIVIDUAL
 # CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
 # EACH HAVING ITS OWN UNIQUE "COMMON NAME",
 # UNCOMMENT THIS LINE OUT.
 ;duplicate-cn
 
 # The keepalive directive causes ping-like
 # messages to be sent back and forth over
 # the link so that each side knows when
 # the other side has gone down.
 # Ping every 10 seconds, assume that remote
 # peer is down if no ping received during
 # a 120 second time period.
 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
 
 # Select a cryptographic cipher.
 # This config item must be copied to
 # the client config file as well.
 ;cipher BF-CBC        # Blowfish (default)
 ;cipher AES-128-CBC   # AES
 ;cipher DES-EDE3-CBC  # Triple-DES 
 
 # Enable compression on the VPN link.
 # If you enable it here, you must also
 # enable it in the client config file.
 comp-lzo
 
 # The maximum number of concurrently connected
 # clients we want to allow.
 ;max-clients 100
 
 # It's a good idea to reduce the OpenVPN
 # daemon's privileges after initialization.
 #
 # You can uncomment this out on
 # non-Windows systems.
 ;user nobody
 ;group nobody
 
 # The persist options will try to avoid
 # accessing certain resources on restart
 # that may no longer be accessible because
 # of the privilege downgrade.
 persist-key
 persist-tun
 
 # Output a short status file showing
 # current connections, truncated
 # and rewritten every minute.
 status openvpn-status.log
 
 # By default, log messages will go to the syslog (or
 # on Windows, if running as a service, they will go to
 # the "\Program Files\OpenVPN\log" directory).
 # Use log or log-append to override this default.
 # "log" will truncate the log file on OpenVPN startup,
 # while "log-append" will append to it.  Use one
 # or the other (but not both).
 log        /var/log/openvpn.log
 log-append /var/log/openvpn.log
 
 # Set the appropriate level of log
 # file verbosity.
 #
 # 0 is silent, except for fatal errors
 # 4 is reasonable for general usage
 # 5 and 6 can help to debug connection problems
 # 9 is extremely verbose
 verb 3
 
 # Silence repeating messages.  At most 20
 # sequential messages of the same message
 # category will be output to the log.
 ;mute 20
 

FIREWALL

The script neede for your firewall can be written outside the firewall script, and loaded when openvpn service starts.

File: /etc/openvpn/HOSTNAME/firewall.up
#!/bin/bash

### If you don't have LogAccept chain already, add it
### and rules to log packets and accept them
/sbin/iptables -N LogAccept
/sbin/iptables -A LogAccept -j LOG --log-level warning --log-prefix 'ACCEPT ' --log-tcp-sequence --log-ip-options --log-tcp-options
/sbin/iptables -A LogAccept -j ACCEPT

/sbin/iptables -I INPUT -p udp --dport 1194 -j LogAccept
/sbin/iptables -I OUTPUT -p udp --sport 1194 -j LogAccept
/sbin/iptables -I FORWARD -s 192.168.139.0/24 -d 192.168.143.0/24 -j LogAccept
/sbin/iptables -I FORWARD -d 192.168.139.0/24 -s 192.168.143.0/24 -j LogAccept


File: /etc/openvpn/HOSTNAME/firewall.down
#!/bin/bash

/sbin/iptables -D INPUT -p udp --dport 1194 -j LogAccept
/sbin/iptables -D OUTPUT -p udp --sport 1194 -j LogAccept
/sbin/iptables -D FORWARD -s 192.168.139.0/24 -d 192.168.143.0/24 -j LogAccept
/sbin/iptables -D FORWARD -d 192.168.139.0/24 -s 192.168.143.0/24 -j LogAccept

### Remove LogAccept rules and chain
/sbin/iptables -D LogAccept -j LOG --log-level warning --log-prefix 'ACCEPT ' --log-tcp-sequence --log-ip-options --log-tcp-options
/sbin/iptables -D LogAccept -j ACCEPT
/sbin/iptables -X LogAccept

Need somes explications ...

SCRIPT

For Installation on Windows Client

This script generates a ZIP file with the kit neccesary to install the openvpn client on a Microsoft Windows System. It needs some files to work properly on Windows System:

unzip.exe
openvpn-2.0.2-gui-1.0.3-install.exe
File: /root/SCRIPT/openvpn/openvpn.sh

 #!/bin/bash
 # Use with a certificate username
 if [ ! $1 ]; then
        echo "Error: specify a username!"
        exit
 fi
 # VAR
 echo $1
 hostname="HOSTNAME"
 certdir="/usr/share/openvpn/easy-rsa"
 openvpndirserver="/usr/share/openvpn/easy-rsa/keys"
 openvpndirclient="/usr/share/openvpn/easy-rsa/keys-client"
 USERCERT="$1"
 tempdir="/tmp"
 dir="$tempdir/$1"
 # CHECK
 if [ -d $dir ]; then
        rm -fr $dir
 fi
 mkdir -p $dir
 batch="$dir/$1.bat"
 # CREATION
 echo "----- Certificate creation"
 cd $certdir
 source ./vars-client
 ./build-key-pass $1
 cd /root
 echo "----- Certificate compression in /tmp/$1"
 cp $openvpndirclient/$USERCERT.* $tempdir
 cp $openvpndirserver/ca.crt $tempdir
 cp /etc/openvpn/$hostname/ta.key $tempdir
 cd $tempdir
 /usr/bin/zip $dir/$USERCERT.zip $USERCERT.* ca.crt ta.key
 rm -f $USERCERT.*
 rm -f ca.crt
 echo "----- Batch installation file for certificates OpenVPN on Windows System"
 echo "if not exist \"%ProgramFiles%\\OpenVPN\\config\" goto EXIT" >> $batch
 echo "if not exist \"%USERPROFILE%\" goto EXITDOC" >> $batch
 echo "set CERT=$USERCERT" >> $batch
 echo "mkdir \"%USERPROFILE%\\openvpn\"" >> $batch
 echo "rem FILE CONFIGURAZIONE" >> $batch
 echo "if not exist \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\" goto NEWFILE" >> $batch
 echo "echo Il file mars.ovpn esiste gia\', sovrascriverlo\?" >> $batch
 echo "del /p \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "if exist \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\" goto EXITABORT" >> $batch
 echo ":NEWFILE" >> $batch
 echo "echo client >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo dev tun >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo proto udp >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo remote 137.204.143.2 1194 >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo resolv-retry infinite >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo nobind >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo persist-key >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo persist-tun >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo ca \"C:\\\Documents\\ and\\ Settings\\\%USERNAME%\\\openvpn\\\ca.crt\" >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo cert \"C:\\\Documents\\ and\ Settings\\\%USERNAME%\\\openvpn\\\%CERT%.crt\" >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo key \"C:\\\Documents\\ and\\ Settings\\\%USERNAME%\\\openvpn\\\%CERT%.key\" >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo tls-auth \"C:\\\Documents\\ and\\ Settings\\\%USERNAME%\\\openvpn\\\ta.key\" 1 >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo comp-lzo >> \"%ProgramFiles%\OpenVPN\config\mars.ovpn\"" >> $batch
 echo "echo verb 3 >> \"%ProgramFiles%\OpenVPN\config\mars.ovpn\"" >> $batch
 echo "rem UNZIP dei certificati" >> $batch
 echo "unzip %CERT%.zip -d \"C:\\Documents and Settings\\%USERNAME%\\openvpn\"" >> $batch
 echo "echo Successfull" >> $batch
 echo "goto END" >> $batch
 echo ":EXIT" >> $batch
 echo "echo Error: install first OpenVPN-GUI" >> $batch
 echo "goto END" >> $batch
 echo ":EXITDOC" >> $batch
 echo "echo Error: C:\Documents\ and \Settings" >> $batch
 echo "echo does not exist" >> $batch
 echo "goto END" >> $batch
 echo ":EXITABORT" >> $batch
 echo "echo ABORT" >> $batch
 echo "goto END" >> $batch
 echo ":END" >> $batch
 echo "pause" >> $batch
 
 cd $dir
 echo "----- Batch file conversion for Windows"
 unix2dos $batch
 echo "----- Copy installation files"
 cp /root/SCRIPT/openvpn/unzip.exe $dir
 cp /root/SCRIPT/openvpn/README.txt $dir
 cp /root/SCRIPT/openvpn/openvpn-2.0.2-gui-1.0.3-install.exe $dir
 cd ..
 echo "----- Archive Creation $tempdir/$1.zip"
 cd $tempdir
 /usr/bin/zip -r $1.zip $1
 echo "----- Deleting installation files"
 if [ -d $dir ]; then
        rm -fr $dir
 fi
 echo "----- Installation file: $tempdir/$1.zip"
 echo "----- SEND IT VIA EMAIL TO USER"
 

For installation on Windows client (with expect)

Script for automatic certificate generation. It needs username and password.

Note: To works it needs expect.

File: /root/SCRIPT/openvpn/openvpn-expect.sh
 #!/bin/bash
 # Use with a certificate username and password
 if [ ! $1 ]; then
        echo "Specify Username"
        echo "openvn-expect.sh username password"
        exit
 fi
 if [ ! $2 ]; then
        echo "Specify Password"
        echo "openvn-expect.sh username password"
        exit
 fi
 # VAR
 echo $1
 echo $2
 HOSTNAME="hostname"
 certdir="/usr/share/openvpn/easy-rsa"
 openvpndirserver="/usr/share/openvpn/easy-rsa/keys"
 openvpndirclient="/usr/share/openvpn/easy-rsa/keys-client"
 USERCERT="$1"
 tempdir="/tmp"
 dir="$tempdir/$1"
 if [ -d $dir ]; then
        rm -fr $dir
 fi
 mkdir -p $dir
 batch="$dir/$1.bat"
 # CREATION
 echo "----- Certificate creation"
 cd $certdir
 source ./vars-client
 echo "#!/usr/bin/expect --" > $tempdir/$1.expect
 echo "spawn $certdir/build-key-pass $1" >> $tempdir/$1.expect
 echo "expect \"phrase:\" { send \"$2\r\" }" >> $tempdir/$1.expect
 echo "expect \"phrase:\" { send \"$2\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"MARS\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"$1@arces.unibo.it\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"\r\" }" >> $tempdir/$1.expect
 echo "expect \":\" { send \"y\r\" }" >> $tempdir/$1.expect
 echo "expect \"\]\" { send \"y\r\" }" >> $tempdir/$1.expect
 echo "expect eof { exit }" >> $tempdir/$1.expect
 chmod 700 $tempdir/$1.expect
 $tempdir/$1.expect
 cd /root
 echo "----- Certificate compression in /tmp/$1"
 cp $openvpndirclient/$USERCERT.* $tempdir
 cp $openvpndirserver/ca.crt $tempdir
 cp /etc/openvpn/mars-fw/ta.key $tempdir
 cd $tempdir
 /usr/bin/zip $dir/$USERCERT.zip $USERCERT.* ca.crt ta.key
 rm -f $USERCERT.*
 rm -f ca.crt
 echo "----- Batch installation file for certificates OpenVPN on Windows System"
 echo "if not exist \"%ProgramFiles%\\OpenVPN\\config\" goto EXIT" >> $batch
 echo "if not exist \"%USERPROFILE%\" goto EXITDOC" >> $batch
 echo "set CERT=$USERCERT" >> $batch
 echo "mkdir \"%USERPROFILE%\\openvpn\"" >> $batch
 echo "rem FILE CONFIGURAZIONE" >> $batch
 echo "if not exist \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\" goto NEWFILE" >> $batch
 echo "echo File $HOSNAME.ovpn already exists, overwrite\?" >> $batch
 echo "del /p \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "if exist \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\" goto EXITABORT" >> $batch
 echo ":NEWFILE" >> $batch
 echo "echo client >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo dev tun >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo proto udp >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo remote 137.204.143.2 1194 >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo resolv-retry infinite >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo nobind >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo persist-key >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo persist-tun >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo ca \"C:\\\Documents\\ and\\ Settings\\\%USERNAME%\\\openvpn\\\ca.crt\" >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo cert \"C:\\\Documents\\ and\ Settings\\\%USERNAME%\\\openvpn\\\%CERT%.crt\" >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo key \"C:\\\Documents\\ and\\ Settings\\\%USERNAME%\\\openvpn\\\%CERT%.key\" >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo tls-auth \"C:\\\Documents\\ and\\ Settings\\\%USERNAME%\\\openvpn\\\ta.key\" 1 >> \"%ProgramFiles%\\OpenVPN\\config\\mars.ovpn\"" >> $batch
 echo "echo comp-lzo >> \"%ProgramFiles%\OpenVPN\config\mars.ovpn\"" >> $batch
 echo "echo verb 3 >> \"%ProgramFiles%\OpenVPN\config\mars.ovpn\"" >> $batch
 echo "rem UNZIP dei certificati" >> $batch
 echo "unzip %CERT%.zip -d \"C:\\Documents and Settings\\%USERNAME%\\openvpn\"" >> $batch
 echo "echo Successfull" >> $batch
 echo "goto END" >> $batch
 echo ":EXIT" >> $batch
 echo "echo Error: install first OpenVPN-GUI" >> $batch
 echo "goto END" >> $batch
 echo ":EXITDOC" >> $batch
 echo "echo Error: C:\Documents\ and \Settings" >> $batch
 echo "echo does not exist" >> $batch
 echo "goto END" >> $batch
 echo ":EXITABORT" >> $batch
 echo "goto END" >> $batch
 echo ":END" >> $batch
 echo "pause" >> $batch
 
 cd $dir
 echo "----- Batch file conversion for Windows"
 unix2dos $batch
 echo "----- Copy installation files"
 cp /root/SCRIPT/openvpn/unzip.exe $dir
 cp /root/SCRIPT/openvpn/README.txt $dir
 cp /root/SCRIPT/openvpn/openvpn-2.0.2-gui-1.0.3-install.exe $dir
 cd ..
 echo "----- Archive Creation $tempdir/$1.zip"
 cd $tempdir
 /usr/bin/zip -r $1.zip $1
 echo "----- Deleting installation files"
 if [ -d $dir ]; then
        rm -fr $dir
 fi
 echo "----- Installation file: $tempdir/$1.zip"
 echo "----- SEND IT VIA EMAIL TO USER"

 

For Installation on Linux Client

Create the configuration file /etc/openvpn/openvpn.conf

File: /etc/openvpn/openvpn.conf
client
dev tun
proto udp
remote FW-IP 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca "/home/username/.openvpn/FW-HOSTNAMEm/ca.crt"
cert "/home/username/.openvpn/FW-HOSTNAMEm/USERNAME.crt"
key "/home/username/.openvpn/FW-HOSTNAMEm/USRNAME.key"
tls-auth "/home/username/.openvpn/FW-HOSTNAME/ta.key" 1
comp-lzo
verb 3

Firewall configuration

File: /etc/openvpn/openvpn.conf
……
verb 3
up /etc/openvpn/firewall.up
down /etc/openvpn/firewall.down
File: /etc/openvpn/firewall.up
#!/bin/bash
/sbin/iptables -I INPUT -p udp --dport 1194 -j ACCEPT
/sbin/iptables -I OUTPUT -p udp --sport 1194 -j ACCEPT
/sbin/iptables -I FORWARD -s 192.168.139.0/24 -d 192.168.143.0/24 -j ACCEPT
/sbin/iptables -I FORWARD -d 192.168.139.0/24 -s 192.168.143.0/24 -j ACCEPT
File: /etc/openvpn/firewall.down
#!/bin/bash
/sbin/iptables -D INPUT -p udp --dport 1194 -j LogAccept
/sbin/iptables -D OUTPUT -p udp --sport 1194 -j LogAccept
/sbin/iptables -D FORWARD -s 192.168.139.0/24 -d 192.168.143.0/24 -j ACCEPT
/sbin/iptables -D FORWARD -d 192.168.139.0/24 -s 192.168.143.0/24 -j ACCEPT
Retrieved from "http://www.gentoo-wiki.info/HOWTO_OpenVPN_RoadWarrior"

Last modified: Thu, 04 Sep 2008 04:09:00 +0000 Hits: 22,701