Installation und Einrichtung eines OpenVPN Client unter FreeBSD
Die Schritte zur Installation und Konfiguration des Kernels entnehmen Sie Bitte dem Kapitel OpenVPN Serverinstallation
In der Filiale läuft ein FreeBSD Server.
Wir bringen nun die folgenden Dateien auf die FreeBSD. Gespeichert werden die Dateien unter /usr/local/etc/openvpn. Auch hier gilt wieder Nutzen Sie unbedingt eine gesicherte Verbindung, oder transportieren sie die Dateien mit einem physischen Datenträger, den Sie hinterher vernichten!:
- vpn-ca.pem
- filialecert.pem
- filialekey.pem
Zusätzlich kopieren wir noch die Konfigurationsdatei client.conf auf die FreeBSD. Wir entziehen die Berechtigungen für die Datei verwaltung.pem:
TTY
# chmod 0600 verwaltungkey.pem
#
Wir kopieren unser Startscript von dem FreeBSD Server auf die Machine ins Verzeichnis /usr/local/etc/rc.d.
Jetzt müssen wir das Kernel Modul tun laden:
TTY
# kldload tun
#
Wir editieren unsere Datei client.conf und passen Sie wie folgt an:
client
float
dev tun
tun-mtu 1492
fragment 1300
mssfix
proto udp
remote 1.1.1.1 443
tls-remote server
ca /usr/local/etc/openvpn/vpn-ca.pem
cert /usr/local/etc/openvpn/verwaltungcert.pem
key /usr/local/etc/openvpn/verwaltungkey.pem
auth SHA1
cipher aes-256-cbc
nobind
comp-lzo
persist-key
persist-tun
verb 3
Das war es schon, wir starten den OpenVPN Client mit der Hoffung auf folgende Ausgabe:
TTY
# openvpn --config /etc/openvpn/client.conf
Sat Apr 30 12:30:38 2005 OpenVPN 2.0 i586-suse-linux [SSL] [LZO] [EPOLL]
built on Apr 30 2005
Sat Apr 30 12:30:38 2005 IMPORTANT:
OpenVPN's default port number is now 1194, based on an official port number
assignment by IANA.
OpenVPN 2.0-beta16 and earlier used 5000 as the default port.
Sat Apr 30 12:30:38 2005 LZO compression initialized
Sat Apr 30 12:30:38 2005 WARNING: normally if you use --mssfix and/or
--fragment, you should also set --tun-mtu 1500 (currently it is 1300)
Sat Apr 30 12:30:38 2005 Control Channel MTU parms
[ L:1362 D:138 EF:38 EB:0 ET:0 EL:0 ]
Sat Apr 30 12:30:38 2005 Data Channel MTU parms
[ L:1362 D:1100 EF:62 EB:23 ET:0 EL:0 AF:3/1 ]
Sat Apr 30 12:30:38 2005 Fragmentation MTU parms
[ L:1362 D:1100 EF:61 EB:23 ET:1 EL:0 AF:3/1 ]
Sat Apr 30 12:30:38 2005 Local Options hash (VER=V4): '1384ad9f'
Sat Apr 30 12:30:38 2005 Expected Remote Options hash (VER=V4): '680ec5fe'
Sat Apr 30 12:30:38 2005 UDPv4 link local: [undef]
Sat Apr 30 12:30:38 2005 UDPv4 link remote: 1.1.1.1:443
Sat Apr 30 12:30:38 2005 TLS: Initial packet from 1.1.1.1:443,
sid=4d8262ad e43004c2
Sat Apr 30 12:30:38 2005 VERIFY OK:
depth=1, /C=de/ST=Niedersachsen/L=Bad_Essen/O=pronix/OU=Administration
/CN=my-ca/emailAddress=you@mail.address
Sat Apr 30 12:30:39 2005 VERIFY X509NAME OK:
/C=de/ST=Niedersachsen/L=Bad_Essen/O=pronix/OU=Administration
/CN=server/emailAddress=you@mail.address
Sat Apr 30 12:30:39 2005 VERIFY OK:
depth=0, /C=de/ST=Niedersachsen/L=Bad_Essen/O=pronix/OU=Administration/
CN=server/emailAddress=you@mail.address
Sat Apr 30 12:30:39 2005 Data Channel Encrypt:
Cipher 'AES-256-CBC' initialized with 256 bit key
Sat Apr 30 12:30:39 2005 Data Channel Encrypt:
Using 160 bit message hash 'SHA1' for HMAC authentication
Sat Apr 30 12:30:39 2005 Data Channel Decrypt:
Cipher 'AES-256-CBC' initialized with 256 bit key
Sat Apr 30 12:30:39 2005 Data Channel Decrypt:
Using 160 bit message hash 'SHA1' for HMAC authentication
Sat Apr 30 12:30:39 2005 Control Channel: TLSv1, cipher TLSv1/SSLv3
DHE-RSA-AES256-SHA, 1024 bit RSA
Sat Apr 30 12:30:39 2005 [server] Peer Connection Initiated with 1.1.1.1:443
Sat Apr 30 12:30:40 2005 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1)
Sat Apr 30 12:30:40 2005 PUSH: Received control message:
'PUSH_REPLY,route 192.168.0.0 255.255.255.0,route 10.8.0.1,
ping 10,ping-restart 120,ifconfig 10.8.0.14 10.8.0.13'
Sat Apr 30 12:30:40 2005 OPTIONS IMPORT: timers and/or timeouts modified
Sat Apr 30 12:30:40 2005 OPTIONS IMPORT: --ifconfig/up options modified
Sat Apr 30 12:30:40 2005 OPTIONS IMPORT: route options modified
Sat Apr 30 12:30:40 2005 TUN/TAP device tun0 opened
Sat Apr 30 12:30:40 2005 /sbin/ifconfig tun0 10.8.0.14
pointopoint 10.8.0.9 mtu 1492
Sat Apr 30 12:30:40 2005 /sbin/route add -net
192.168.0.0 netmask 255.255.255.0 gw 10.8.0.13
Sat Apr 30 12:30:40 2005 /sbin/route add -net
10.8.0.1 netmask 255.255.255.255 gw 10.8.0.13
Sat Apr 30 12:30:40 2005 Initialization Sequence Completed
Nun setzen wir einen ping auf das Netzwerk ab, um zu sehen, ob alles klappt:
TTY
# ping -c 3 192.168.0.3
PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data.
64 bytes from 192.168.0.3: icmp_seq=1 ttl=64 time=0.613 ms
64 bytes from 192.168.0.3: icmp_seq=2 ttl=64 time=0.589 ms
64 bytes from 192.168.0.3: icmp_seq=3 ttl=64 time=0.628 ms
--- 192.168.0.3 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.589/0.610/0.628/0.016 ms
Hurray, Hurray :-D
Automatischer Start des Client
Wir wollen natürlich OpenVPN nicht nach dem Booten des Servers manuell starten und fügen deshalb die folgenden Variablen in die Datei /etc/rc.conf ein:
# Openvpn
openvpn_enable="YES"
openvpn_if="tun tap"
openvpn_configfile="/usr/local/etc/openvpn/client.conf"
openvpn_dir="/usr/local/etc/openvpn"
Falls Sie eine ältere OpenVPN-Version nutzen, können Sie alternativ auch ein Startscript unter /usr/local/etc/rc.d/openvpn.sh erstellen.
In der OpenVPN Distribution ist ein Beispiel für RedHat enthalten, dass wir für unseren FreeBSD Server anpassen.
#!/bin/sh
# Unser OpenVPN binary
openvpn="/usr/local/sbin/openvpn"
# OpenVPN Verzeichnis
work="/usr/local/etc/openvpn"
# Lockfile
lock="openvpn.lock"
# PID Verzeichnis
piddir="/var/run"
#########################
# Here we go #
#########################
lock="$work/$lock"
if ! [ -f $openvpn ]; then
echo "Error: OpenVPN binary not found"
exit 0;
fi
# Unsere Optionen, die wir dem Startscript mitgeben koennen
case "$1" in
start)
if ! `/sbin/kldstat | grep -q if_tap\.ko`; then
if ! `/sbin/kldload if_tap`; then
echo "Error: Can't load kernel module if_tap"
exit 0;
fi
fi
if [ -e $lock ]; then
echo "OpenVPN is already running. Trying to kill..."
for pidf in `/bin/ls $piddir/openvpn*.pid 2>/dev/null`; do
if [ -s $pidf ]; then
kill `cat $pidf` >/dev/null 2>&1
fi
rm -f $pidf
done
rm -f $lock
sleep 3
fi
rm -f $piddir/openvpn*.pid
cd $work
success=0
for c in `/bin/ls *.conf 2>/dev/null`; do
bn=${c%%.conf}
rm -f $piddir/$bn.pid
$openvpn --daemon --writepid $piddir/openvpn$bn.pid --config $c --cd $work
if [ $? -eq 0 ]; then
echo "OpenVPN: Startet with configuration $c"
success=1
fi
done
if [ $success -eq 1 ]; then
touch $lock
fi
;;
stop)
for pidf in `/bin/ls $piddir/openvpn*.pid 2>/dev/null`; do
if [ -s $pidf ]; then
kill `cat $pidf` >/dev/null 2>&1
fi
rm -f $pidf
done
rm -f $lock
if `/sbin/kldstat | grep -q if_tap\.ko`; then
if ! `/sbin/kldunload if_tap`; then
echo "Error: Can't unload kernel module if_tap"
exit 0;
fi
fi
echo "Stopped OpenVPN"
;;
restart)
$0 stop
sleep 3
$0 start
;;
reload)
if [ -f $lock ]; then
for pidf in `/bin/ls $piddir/openvpn*.pid 2>/dev/null`; do
if [ -s $pidf ]; then
kill -USR1 `cat $pidf` >/dev/null 2>&1
fi
done
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
;;
esac
exit 0
Weiter mit Absicherung nach der Einrichtung
