Hallo erstmal,
Trotz diverser Problemberichte in anderen Foren zum Thema qnap und gebridgetes OpenVPN auf Basis eines tap-devices mit udp-Protokoll, habe ich mir ein NAS-TS 110 gekauft und einen OpenVPN-Client zur Anbindung an einen Linux-Server gescriptet.
Man soll ja nicht nur nehmen, sondern auch geben. Deshalb hier für alle dies interessiert das Ergebnis. Das Ding funktioniert seit Tagen einwandfrei und hält klaglos die Verbindung offen - wies soll
#!/bin/sh##################################################################################################### Startvorbereitung und Start von OpenVPN # auf dem NAS-TS 110. Wird aufgerufen von der autorun.sh# bzw kann in die autorun.sh gelinkt werden.# Liegt in /share/HDA_DATA/.qpkg/Optware/etc/openvpn/start.sh# Bei den derzeitigen Einstellungen wird ein TAP-Device erstellt# und die Verbindung erfolgt gebrückt, d.h. im selben Subnetz wie# der angesprochene Server auf Basis des udp-Protokolls########################################################################################## parameter-declarations## search-pathsPS="/bin/ps"GREP="/bin/grep"MKDIR="/bin/mkdir"RM="/bin/rm"PING="/bin/ping"INSMOD="/sbin/insmod"LSMOD="/sbin/lsmod"IFCONFIG="/sbin/ifconfig"ROUTE="/sbin/route"OPENVPN="/share/HDA_DATA/.qpkg/Optware/sbin/openvpn"BRCTL="/opt/sbin/brctl"## variablesbr="br0"eth="eth0"tap="tap0"eth_ip="10.1.1.101"eth_netmask="255.255.255.0"eth_gateway="10.1.1.200"MNLogDir="/share/HDA_DATA/.qpkg/Optware/etc/openvpn/log"MNLogFile=$MNLogDir"/boot.log"MNDebug=1########################################################################################## Routine zur Logbucherstellung beim Boot des NAS########################################################################################## Function log()log(){ local logtext="$1" # ether no debug-message or debug-message and debug-flag set if ( test $# -lt 2 ) || ( ( test $# -eq "2" ) && (($MNDebug)) ); then # Protokollierung if !(test $MNLogFile = ""); then echo -n $(date +%c)' : ' >> $MNLogFile if (test "$logtext" = ""); then echo $0 >> $MNLogFile elif (test "$logtext" = "-"); then echo "--------------------------------------------------" >> $MNLogFile else echo $logtext >> $MNLogFile fi fi # all right to log-file chmod 777 $MNLogFile fi}# eoFunction#########################################################################################log "last vpn-check" -debug# create log-dir$MKDIR -p $MNLogDir# und alte log-Datei löschen$RM $MNLogFilelog "preparing boot of openvpn"# wait for DSLlog "waiting for internet connection" -debuguntil ($PING -c 1 www.heise.de > /dev/null 2>&1); do sleep 5 done log "internet online" -debug# load modul for tun$INSMOD /usr/local/modules/tun.ko > /dev/null 2>&1if ($LSMOD | $GREP tun); then log "found tun-modul" -debugelse log "no tun-modul" -debug exitfi# load modul for bridge$INSMOD /usr/local/modules/bridge.ko > /dev/null 2>&1if ($LSMOD | $GREP bridge); then log "found bridge-modul" -debugelse log "no bridge-modul" -debug exitfilog "system ready all modules present" -debug# create a tap-device if not presentif !($IFCONFIG -a | $GREP tap0); then # we need a tap-device for a brigded system -> lets do it $OPENVPN --mktun --dev tap0 # if something went wrong if [ ! $? ] ; then log "creating tap-device went wrong!" -debug exit 1 fi # check it until ($IFCONFIG -a | $GREP tap0); do sleep 1 done log "tap0 device created" -debugfi# create the bridge if not presentif !($IFCONFIG -a | $GREP br0); then # add a bridg $BRCTL addbr $br log "bridge $br created" -debug # addd eth in $BRCTL addif $br $eth log "eth-device $eth tied to the bridge" -debug # add tap in $BRCTL addif $br $tap log "tap-device $tap tied to the bridge" -debug # set them to promisc-mode $IFCONFIG $tap 0.0.0.0 promisc up $IFCONFIG $eth 0.0.0.0 promisc up log "both devices set into the promisc-mode" -debug # put the address back to the bridge $IFCONFIG $br $eth_ip netmask $eth_netmask log "given ethernet-ip $eth_ip to the bridge" -debug # and give default gateway to the bridge $ROUTE add default gw $eth_gateway $br log "set default route $eth_gateway to bridge $br" -debugfi # starting OpenVPN$OPENVPN --config /share/HDA_DATA/.qpkg/Optware/etc/openvpn/openvpn.conf --daemon# check the whole thingif ($PS ax | $GREP openvpn | $GREP -v grep > /dev/null 2>&1); then log "openvpn ready to go" -debugelse log "openvpn not started" -debugfi############################################ eof start.sh
Ich habe - wie man sehen kann, peinlich drauf geachtet, daß alle Pfadangaben komplett sind. In der Konsole funktionierts auch ohne - allerdings scheint das Environment während des Bootvorgangs erheblich eingeschränkter zu sein.
Nun zum Thema meiner Frage:
Wie gesagt aus der Konsole läufts einwandfrei, starte ich das Script allerding als autorun.sh dann führt er die Zeile
nicht korrekt aus. Übergeht die Abarbeitungsprüfung
# if something went wrong if [ ! $? ] ; then log "creating tap-device went wrong!" -debug exit 1 fi
sang- und klanglos als wäre alles in Ordnung und verläuft sich
dann in der until-Schleife - eigendlich ordnungsgemäss, da das Tap-Device nicht korrekt erstellt wurde . . . .
Nun bin ich ein leidlicher Scripter unter full-featured Liunuixiden, die abgespeckte Umgebung des NAS ist für mich Neuland. Habs auch als Cron-Job versucht, da tut sich das ganze mit Prüfroutinen wie
unglaublich schwer . . . hab auch schon an at-jobs gedacht, um eine vernünftige Arbeitsumgebung nach dem Start zu erhalten. Da kann ich - neben der Tatsache ob es at überhaupt fürs nas gibt - nicht einschätzen, ob sich der Installationsaufwand dafür lohnt.
Vielleicht gibts ja bei Euch einen NAS-hardcore-Spezie, der mir weiterhelfen kann oder es hat jemand eine Idee, die mich weiterbringt. Bin für alle Schandtaten offen