OpenVPN (deutsch)

From
Jump to navigation Jump to search

OpenVPN ist eine leicht aufzusetzende und zu wartende Virtual Private Network-Applikation, die bis auf die notwendige virtuelle Netzwerkschnittstelle komplett im Userspace arbeitet. Der gesamte Netzwerkverkehr wird auf Grundlage von OpenSSL verschlüsselt.


Funktionsweise

OpenVPN legt nach dem Start sowohl auf der Client- als auch auf der Serverseite eine virtuelle Netzwerkschnittstelle an (wenn nicht schon vorhanden), welche jeweils ein Ende des Tunnelsdarstellt. Der OpenVPN-Server muss vom Client durch eine feste IP-Addresse oder festen Host-Namen erreichbar sein und verbindet sich mit ihm auf einem beliebigen UDP- oder TCP-Port. Mit den zwei Verbindungsarten Routing und Bridging stehen nun je nach Auswahl fast alle oder jegliche Dienste des lokalen Netzes für den Client zur Verfügung.

Der gesamte Datenverkehr durch den Tunnel wird mittels OpenSSL-Bibliotheken verschlüsselt. Die LZO-Bibliotheken bieten die Option zur Kompression dieser Information.

Benötigte Komponenten

Installation

Windows

Die Installation erfolgt - wie unter Windows üblich - durch Starten der EXE-Datei und wiederholtem Klicken auf Next. Danach findet sich das openvpn-Programm unter \Programme\OpenVPN\bin, die Konfigurationsdateien unter \Programme\OpenVPN\config.

Als unprivilegierter Benutzer starten

Um den Tunnel als normaler Benutzer aufzubauen müssen die Zugriffskontrolllisten für den OpenVPN-Dienst angepasst werden. z.B. mit SetACL oder Subinacl.exe.

Anzeigen der Zugriffsrechte:
setacl -on openvpnservice -ot srv -actn list

Setzen der ACLs für den OpenVPN-Service, so daß Benutzer den Dienst starten und beenden können:
setacl -on openvpnservice -ot srv -actn ace -ace "n:Benutzer;p:start_stop"

Starten des Dienstes via Kommandozeile:
sc start OpenVPNService

Stoppen des Dienstes via Kommandozeile:
sc stop OpenVPNService

Die obigen Maßnahmen erlauben aber noch nicht das Setzen von Routen. Um einem unprivilegiertem Nutzer das Setzen von Routen zu ermöglichen, muss er zur Gruppe der Netzwerkkonfigurations-Operatoren hinzugefügt werden. Wer nach dem Anmelden seine Lieblingsverbindung automatisch starten möchte, muss in der Registry unter HKLM\SOFTWARE/Microsoft\Windows\CurrentVersion\Run den openvpn-gui Eintrag ändern.
openvpn-gui REG_SZ c:\programme\openvpn\bin\openvpn-gui.exe --connect config.ovpn
Dann wird man beim Anmelden, je nach Art der Verbindung, sofort nach Username und Passwort (z.B. für Base1) gefragt.

Unix

Alle handelsüblichen Distributionen bieten mehr oder weniger aktuelle Pakete von OpenVPN an, die i.d.R. die hier angesprochenen Funktionalitäten aufweisen. Eventuell müssen analog empfohlene Zusatzpakete installiert werden (z.B. OpenSSL oder LZO).

Distribution Version(en) Installationskommando (als root)
suse/opensuse >=9.3 yast -i openvpn
gentoo n/a emerge openvpn
FreeBSD 6.0 pkg_add -r openvpn
debian >=3.1 apt-get install openvpn
ubuntu >=5.10 apt-get install openvpn
Fedora Core >=4 yum install openvpn

Sofern keine Paketverwaltungssoftware benutzt werden kann, bleibt noch der Weg über die Quelltexte um an eine aktuelle Version des Programms zu kommen. Das bekannte Drei-Gespann:

./configure
make
make install

sollte bis auf die Angabe der Pfade für Header- und Bibliotheks-Dateien zum Erfolg führen, sofern Compiler und SSL-Bibliotheken (in der Entwicklerversion) installiert sind. Für eine Konfiguration mit lzo unterhalb von /usr/local hilft folgender Aufruf von configure:

./configure --with-lzo-headers=/usr/local/include/ --with-lzo-lib=/usr/local/lib/


Als unprivilegierter Benutzer starten

Da OpenVPN Änderungen an den Netzwerkeinstellungen vornimmt, muss das Programm mit root-Rechten ausgeführt werden. Um den normalen Benutzern nicht das root-Passwort geben zu müssen, kann man statt dessen sudo verwenden. Als root nimmt man mit visudo folgenden Eintrag vor:

# Komma-separierte Liste der VPN-Nutzer
User_Alias VPNUSER=vpnuser1, vpnuser2
# Zum testen des VPN sollte man das --daemon weglassen,
# um evtl. Fehler auf stdout zu erhalten.
Cmnd_Alias OPENVPN=/usr/local/sbin/openvpn --config /etc/openvpn/SAR-VPN.ovpn --daemon
Cmnd_Alias KILLOPENVPN=/usr/bin/killall openvpn
# NOPASSWD ist optional.
# Soll der Nutzer sein Passwort eingeben muessen lautet der Eintrag wie folgt:
#VPNUSER ALL=OPENVPN
#VPNUSER ALL=KILLOPENVPN
VPNUSER ALL=NOPASSWD:OPENVPN
VPNUSER ALL=NOPASSWD:KILLOPENVPN

In diesem Beispiel wird angenommen, dass die Konfigurationsdatei unter /etc/openvpn/SAR-VPN.ovpn und das openvpn-Programm unter /usr/local/sbin/openvpn zu finden ist.

Der Tunnel kann dann mit

sudo /usr/local/sbin/openvpn --config /etc/openvpn/SAR-VPN.ovpn --daemon

gestartet und mit

sudo killall openvpn

beendet werden.

Konfiguration

Grundeinstellung

Ausführlich beschrieben im offiziellen Handbuch; im Wesentlichen läuft es darauf hinaus bei Client und Server zueinander passende Einstellungen zu wählen.

OpenVPN-Client und -Server können sich sowohl über UDP als auch TCP unterhalten. Bei der richtigen Wahl ist zu Bedenken, dass das tap-Device (siehe unten) auf Layer 2 Ebene tunnelt und somit innerhalb des Kanals TCP-Pakete sendet. Da TCP ein Verbindungsorientiertes Protokoll ist, besitz es eine sich selbst anpassende Zeitspanne, nach der ein erneuter Request auf ein nicht angekommenes Paket gesendet wird. Liegt also ein TCP-Layer über einem anderen, beide ausgestattet mit Timer und Resend-Request. Diese Kontrollflusspakete werden zusätzlich zu den eigentlichen Daten gesendet und sind für sie redundant. Wenn die Verbindung im Kanal einen kurzen Timer besitz, werden Resend-Requests über den TCP-Tunnel gesendet und erhöhen so auch das Datenaufkommen außerhalb des Tunnels (die TCP-Pakete der Verbindung, die den Tunnel bildet kann ebenfalls verloren gehen was zu neuen Resend-Requests führt). Durch sich kumulierende Kontrollflusnachrichten erhöht sich der Geschwindigkeitsverlust durch redundante Daten (mehr dazu siehe hier).

Authentifikation

Preshared Key

Die Preshared-Secret-Authentifizierung basiert auf einem symmetrischen Verschlüsselungsverfahren. Mittels openvpn --genkey --secret static.key wird ein gemeinsamer Schlüssel erzeugt, den die beiden Kommunikationspartner zuvor über einen sicheren Kanal erhalten müssen. Der gesamte Tunnel-Netzwerkverkehr wird dann mit diesem Schlüssel verschlüsselt und kann von jedem, der ebenfalls den Schlüssel besitzt entschlüsselt werden. Daher eignet sich jeder Schlüssel für nur genau eine Punkt-zu-Punkt verbindung und muss bei Kompromittierung ausgetauscht werden.

Mittels der beiden folgenden Konfigurationsdateien sollte bereits eine Verbindung zwischen Client und Server möglich sein:

server.conf:

dev tun
ifconfig 10.8.0.1 10.8.0.2
secret static.key

client.conf:

remote myremote.mydomain
dev tun
ifconfig 10.8.0.2 10.8.0.1
secret static.key

Dabei sollte myremote.mydomain in den Hostnamen oder die statische IP des Servers geändert werden. In diesem Beispiel erhalten die virtuellen tun-Schnittstellen die Addressen 10.8.0.1 (Server) und 10.8.0.2 (Client).


Zertifikatbasierte Authentifizierung

Die Zertifikatbasierte Authentifizierung nutzt eine [[Public Key Infrastructure]] (PKI) und basiert auf einem asymmetrischen Verschlüsselungsverfahren, über welches ein sicherer Kanal erzeugt wird. Dabei kommen signierte Zertifikate zum Einsatz, die bei Kompromittierung lediglich gesperrt und gegebenenfalls auf der entsprechenden Maschine durch ein neues ersetzt werden müssen. Ohne ein von der Certificate Authority (CA) signiertes Zertifikat seines Gegenübers akzeptiert kein Kommunikationspartner die Verbindung.

Erstellen einer PKI mit OpenVPN

OpenSSL bringt bereits alle Werkzeuge mit, um eine CA aufzusetzen, um damit Server- und Clientzertifikate sowie die dazugehörigen privaten Schlüssel zu erstellen. OpenVPN besitzt im Unterverzeichnis easy-rsa weitere Skripte, mit denen diese Tools bedient und deren Handhabung noch weiter vereinfacht. Die Bedienung von easy-rsa entnehmen Sie bitte dem OpenVPN-howto.

Die folgende, dem Howto entnommene Tabelle ordnet jeder generierten Datei einen Besitzer zu. Besonders zu beachten ist, dass die als Secret markierten Dateien nur an die dafür vorgesehenen Parteien gegeben werden.

Filename Needed By Purpose Secret
ca.crt server + all clients Root CA certificate NO
ca.key key signing machine only Root CA key YES
dh{n}.pem server only Diffie Hellman parameters NO
server.crt server only Server Certificate NO
server.key server only Server Key YES
client1.crt client1 only Client1 Certificate NO
client1.key client1 only Client1 Key YES
client2.crt client2 only Client2 Certificate NO
client2.key client2 only Client2 Key YES
client3.crt client3 only Client3 Certificate NO
client3.key client3 only Client3 Key YES
Anpassung der .conf bzw. .ovpn Dateien

Sowohl beim Server als auch beim Client ist darauf zu achten, dass die folgenden Zeilen der unten gegebenen Beispielkonfigurationen

ca ca.crt
cert server.crt
key server.key

bzw.

ca ca.crt
cert client.crt
key client.key

auf die für den Server/Client erstellten Dateien zeigen. Sollten Sie nicht mit der unten gegebenen Konfiguration starten, müssen Sie die Preshared-Key-Authentifizierung evtl. deaktivieren.

Benutzername/Passwort

Wahl des virtuellen Device

Auf den OpenVPN-Gateways muss in jedem Fall das IP-Forwarding (Routing) eingestellt sein. Auf Debian-Systemen muss hierzu in der /etc/network/options die Option ip_forward auf yes geändert werden. Suse bietet mittels yast an, dies via Häkchen bei den Netzwerkeinstellungen zu machen. Bei anderen Systemen sollte ein echo 1 > /proc/sys/net/ipv4/ip_forward zum Erfolg führen (muss nach jedem Neustart ausgeführt werden).

tun-Devices

Durch den Tunnel können mit einem dieser Schnittstelle alle gängigen Netzwerkprotokolle auf IP-Basis (Layer 3) transportiert werden. So können Daten vom Fileserver sowie Datenbankinfos abgerufen, ebenso können E-Mails bei einem Mailserver abgeholt werden. Das alles funktioniert, als ob man sich vor Ort befände, weil alle Anfragen zu beliebigen Rechnern im lokalen Netz durchgereicht werden. Interessant ist die Technik auch für Außendienstler (Roadwarrior), die sich von unterwegs in der Zentrale einloggen wollen, um ihre Daten abzugleichen.

Die Kommunikation von drinnen nach draußen funktioniert über mehrere Routen auf Client und Serverseite, daher wird das Verfahren auch Routing genannt. Die Konfigurationsvorlagen sind bereits für den Einsatz des tun-Device ausgelegt.

tap-Devices

Im Gegensatz zu OpenVPN mit einem tun-Device beherrscht die Konfiguration mit einem tap-Device ein vollständiges Tunneln von Ethernet-Frames (Layer 2) und erlaubt somit beispielsweise auch den Einsatz von IPX über einem Tunnel. Ist OpenVPN 2.0 für tap-Devices konfiguriert, bekommen Clients IP-Adressen aus dem Adresspool des Servernetzes. Dies setzt voraus, dass dort bereits ein DHCP-Server seinen Dienst verrichtet. Alternativ kann OpenVPN einen DHCP-Server simulieren und selbst IP-Adressen verteilen.

In den Konfigurationsvorlagen muss dazu die Wahl der Netzwerkschnittstelle geändert werden:

dev tap
;dev tun

Zwei Netze, das virtuelle VPN-Netz und das lokale Netzwerk, werden über eine Brücke miteinander verbunden und unter ein und derselben Subdomain vereint. Das Verfahren nennt man daher auch Bridging.

Szenarien

Außendienst-Mitarbeiter (Netz-zu-Host)

Eine häufiger Anwendungsfall für VPNs beschreibt folgendes Szenario: Ein Außendienst-Mitarbeiter (auch Roadwarrior), Tele-Arbeiter oder einfach jemand der zu Hause noch ein Dokument braucht, möchte Zugriff auf die Ressourcen seines Firmen-Netzes erlangen, welches aus Sicherheitsgründen zum Internet aber durch eine Firewall abgeschottet ist.

In der folgenden Betrachtung wird davon ausgegangen, dass das Firmen-Netzwerk im Subnetz 192.168.0.0/24 liegt. Diese Angaben sind bei der Konfiguration natürlich an die lokalen Gegebenheiten anzupassen. Weiterhin soll für als Subnetz, in welchem sich die VPN-Clients befinden, 192.168.10.0/24 angenommen werden.

Für kleine Netzwerke kann für dieses Szenario auch der Peer-to-Peer-Modus (mit Shared-Secret-Authentifizierung) von OpenVPN verwendet werden. Der Administrationsaufwand steigt bei dieser Realisierung mit der Größe des VPN-Netzes - also mit der Anzahl der VPN-Clients. Außerdem muss pro Client auf der Serverseite ein expliziter Daemon-Prozess mit separatem UDP-Port laufen, was zudem die Firewall-Konfiguration aufwändiger gestaltet. Im folgenden wird daher der Server-Client-Modus von OpenVPN (ab Version 2) mit Hilfe von zertifikatbasierter Authentifizierung beschrieben.


Transparente Fillialanbindung (Netz-zu-Netz)

Für dieses Szenario kann die Konfiguration aus dem ersten Test verwendet werden. Es wird dann kein expliziter Server ausgewiesen und es braucht keine PKI aufgesetzt werden. Man muss nur den gemeinsamen Schlüssel über einen sicheren Kanal übertragen, z.B. eine verschlüsselte E-Mail.

Sinnvollerweise kann man die Optionen wie im o.g. Szenario in eine Datei schreiben und ein paar zusätzliche Optionen, wie das automatische Setzen von Routen angeben.

Eine Beispiel-Konfiguration wäre also:

##############################################################################
# /etc/openvpn/openvpn-gateway.ovpn
#
# Diese Konfiguartionsdatei beinhaltet Einstellungen
# fuer einen OpenVPN-Gateway.
#
# Mit
#   openvpn --config /etc/openvpn/openvpn-gateway.ovpn
# kann das Gateway gestartet werden.
remote 192.168.10.2
;remote 192.168.10.1  # auf der anderen Tunnelseite
ifconfig 192.168.10.1 192.168.10.2
;ifconfig 192.168.10.2 192.168.10.1  # auf der anderen Tunnelseite

proto udp
port 5000
dev tun
cd /etc/openvpn
secret preshared.key
keepalive 10 60
comp-lzo
user nobody
group nobody
persist-key
persist-tun
verb 4
;daemon # Sollte erst nach fertiger Konfiguration aktiviert werden

Will man mehrere Fillialen an eine Zentrale anbinden, wird man eher zum oben genannten Netz-zu-Host-Szenario greifen. Hierbei spielt das Gateway in der Zentrale die Rolle des Servers und das Gateway der Filliale die Rolle des Clients. Eventuell muss auf Server-Seite noch ein clientspezifisches Skript mit entsprechenden Routing-Eintragungen eingesetzt werden, falls in der Zentrale ein Rechner aus dem Netz der Filliale erreicht werden soll.

Extra-Sicherheit

Nachdem die Virtuellen Netzwerkkarten kreiert und die Routen gelegt sind, bietet OpenVPN unter Unix die Option seine Rechte zu reduzieren. Der Kommentar vor den folgenden Zeilen sollte bei den Konfigurationsvorlagen entfernt werden.

;user nobody
;group nobody

Falls also je eine Sicherheitslücke entdeckt werden sollte, kann der OpenVPN-Prozess nicht missbraucht werden. Zusätzlich kann man ihn mit Einfügen der folgenden Zeile an ein bestimmtes Verzeichnis binden:

chroot /usr/local/openvpn

Konfigurationsvorlagen

Die folgenden Beispielkonfigurationsdateien wurden dem OpenVPN-Paket entnommen.

server.conf

#################################################
# Sample OpenVPN 2.0 config file for            #
# multi-client server.                          #
#                                               #
# This file is for the server side              #
# of a many-clients <-> one-server              #
# OpenVPN configuration.                        #
#                                               #
# OpenVPN also supports                         #
# single-machine <-> single-machine             #
# configurations (See the Examples page         #
# on the web site for more info).               #
#                                               #
# This config should work on Windows            #
# or Linux/BSD systems.  Remember on            #
# Windows to quote pathnames and use            #
# double backslashes, e.g.:                     #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
#                                               #
# Comments are preceded with '#' or ';'         #
#################################################
# Which local IP address should OpenVPN
# listen on? (optional)
;local a.b.c.d
# 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 tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# 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 ca.crt
cert server.crt
key 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 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
# 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 192.168.10.0 255.255.255.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
# 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"
# 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         openvpn.log
;log-append  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


client.conf

##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server.     #
#                                            #
# This configuration can be used by multiple #
# clients, however each client should have   #
# its own cert and key files.                #
#                                            #
# On Windows, you might want to rename this  #
# file so it has a .ovpn extension           #
##############################################
# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client
# Use the same setting as you are using on
# the server.
# 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,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap
# Are we connecting to a TCP or
# UDP server?  Use the same setting as
# on the server.
;proto tcp
proto udp
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote my-server-1 1194
;remote my-server-2 1194
# Choose a random host from the remote
# list for load-balancing.  Otherwise
# try hosts in the order specified.
;remote-random
# Keep trying indefinitely to resolve the
# host name of the OpenVPN server.  Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite
# Most clients don't need to bind to
# a specific local port number.
nobind
# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nobody
# Try to preserve some state across restarts.
persist-key
persist-tun
# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here.  See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]
# Wireless networks often produce a lot
# of duplicate packets.  Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings
# SSL/TLS parms.
# See the server config file for more
# description.  It's best to use
# a separate .crt/.key file pair
# for each client.  A single ca
# file can be used for all clients.
ca ca.crt
cert client.crt
key client.key
# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server".  This is an
# important precaution to protect against
# a potential attack discussed here:
#  http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server".  The build-key-server
# script in the easy-rsa folder will do this.
;ns-cert-type server
# If a tls-auth key is used on the server
# then every client must also have the key.
;tls-auth ta.key 1
# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x
# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo
# Set log file verbosity.
verb 3
# Silence repeating messages
;mute 20

firewall.sh

Das folgende Skript nutzt die Linux-Kernel-Erweiterung netfilter, um eine Firewall zu errichten. Lediglich UDP-Verbindungen auf dem Port 1194 werden nicht geblockt. Auf diesem Port sollte der OpenVPN-Server horchen, um eine Verbindung des Clients mit der virtuellen tun/tap-Schnittstelle des Servers zu ermöglichen. Jene Schnittstelle besitzt im Gegensatz zu anderen Netzwerkkarten alle Rechte zum FORWARD, INPUT und OUTPUT.

#!/bin/bash
# A Sample OpenVPN-aware firewall.
# eth0 is connected to the internet.
# eth1 is connected to a private subnet.
# Change this subnet to correspond to your private
# ethernet subnet.  Home will use HOME_NET/24 and
# Office will use OFFICE_NET/24.
PRIVATE=10.0.0.0/24
# Loopback address
LOOP=127.0.0.1
# Delete old iptables rules
# and temporarily block all traffic.
iptables -P OUTPUT DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -F
# Set default policies
iptables -P OUTPUT ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
# Prevent external packets from using loopback addr
iptables -A INPUT -i eth0 -s $LOOP -j DROP
iptables -A FORWARD -i eth0 -s $LOOP -j DROP
iptables -A INPUT -i eth0 -d $LOOP -j DROP
iptables -A FORWARD -i eth0 -d $LOOP -j DROP
# Anything coming from the Internet should have a real Internet address
iptables -A FORWARD -i eth0 -s 192.168.0.0/16 -j DROP
iptables -A FORWARD -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A FORWARD -i eth0 -s 10.0.0.0/8 -j DROP
iptables -A INPUT -i eth0 -s 192.168.0.0/16 -j DROP
iptables -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP
iptables -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP
# Block outgoing NetBios (if you have windows machines running
# on the private subnet).  This will not affect any NetBios
# traffic that flows over the VPN tunnel, but it will stop
# local windows machines from broadcasting themselves to
# the internet.
iptables -A FORWARD -p tcp --sport 137:139 -o eth0 -j DROP
iptables -A FORWARD -p udp --sport 137:139 -o eth0 -j DROP
iptables -A OUTPUT -p tcp --sport 137:139 -o eth0 -j DROP
iptables -A OUTPUT -p udp --sport 137:139 -o eth0 -j DROP
# Check source address validity on packets going out to internet
iptables -A FORWARD -s ! $PRIVATE -i eth1 -j DROP
# Allow local loopback
iptables -A INPUT -s $LOOP -j ACCEPT
iptables -A INPUT -d $LOOP -j ACCEPT
# Allow incoming pings (can be disabled)
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
# Allow services such as www and ssh (can be disabled)
iptables -A INPUT -p tcp --dport http -j ACCEPT
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
# Allow incoming OpenVPN packets
# Duplicate the line below for each
# OpenVPN tunnel, changing --dport n
# to match the OpenVPN UDP port.
#
# In OpenVPN, the port number is
# controlled by the --port n option.
# If you put this option in the config
# file, you can remove the leading '--'
#
# If you taking the stateful firewall
# approach (see the OpenVPN HOWTO),
# then comment out the line below.
iptables -A INPUT -p udp --dport 1194 -j ACCEPT
# Allow packets from TUN/TAP devices.
# When OpenVPN is run in a secure mode,
# it will authenticate packets prior
# to their arriving on a tun or tap
# interface.  Therefore, it is not
# necessary to add any filters here,
# unless you want to restrict the
# type of packets which can flow over
# the tunnel.
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT
# Allow packets from private subnets
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -j ACCEPT
# Keep state of connections from local machine and private subnets
iptables -A OUTPUT -m state --state NEW -o eth0 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -m state --state NEW -o eth0 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
# Masquerade local subnet
iptables -t nat -A POSTROUTING -s $PRIVATE -o eth0 -j MASQUERADE


Literatur