Determine a interface virtual com ifconfig
:
tap0 Link encap:Ethernet HWaddr 32:28:a4:04:34:cc
inet addr:172.22.18.14 Bcast:172.22.18.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
e desligue-o com:
sudo ifconfig tap0 down
Aqui está o script de inicialização que eu escrevi para o RedHat:
#! /bin/bash
#
# openvpn-client Start/Stop the openvpn client
#
# chkconfig: 2345 90 60
# description: start openvpn client at boot
# processname: openvpn
# Source function library.
. /etc/init.d/functions
daemon="openvpn"
prog="openvpn-client"
conf_file="/vagrant/vpn/client-dept18-payment.ovpn"
start() {
echo -n $"Starting $prog: "
if [ -e /var/lock/subsys/openvpn-client ] && [ $(pgrep -fl "openvpn --config /vagrant/vpn/client-dept18-payment.ovpn" | wc -l) -gt 0 ]; then
echo_failure
echo
exit 1
fi
runuser -l root -c "$daemon --config $conf_file >/dev/null 2>&1 &" && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/openvpn-client;
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
pid=$(ps -ef | grep "[o]penvpn --config $conf_file" | awk '{ print $2 }')
kill $pid > /dev/null 2>&1 && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/openvpn-client;
return $RETVAL
}
status() {
pgrep -fl "openvpn --config /vagrant/vpn/client-dept18-payment.ovpn" >/dev/null 2>&1
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
pid=$(ps -ef | grep "[o]penvpn --config $conf_file" | awk '{ print $2 }')
echo $"$prog (pid $pid) is running..."
else
echo $"$prog is stopped"
fi
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
condrestart)
[ -f /var/lock/subsys/openvpn-client ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
então você pode usá-lo como de costume:
# /etc/init.d/openvpn-client start
Starting openvpn-client: [ OK ]
# /etc/init.d/openvpn-client start
Starting openvpn-client: [FAILED]
# /etc/init.d/openvpn-client status
openvpn-client (pid 5369) is running...
# /etc/init.d/openvpn-client stop
Stopping openvpn-client: [ OK ]
# /etc/init.d/openvpn-client stop
Stopping openvpn-client: [FAILED]
# /etc/init.d/openvpn-client status
openvpn-client is stopped
# /etc/init.d/openvpn-client restart
Stopping openvpn-client: [ OK ]
Starting openvpn-client: [ OK ]
# /etc/init.d/openvpn-client status
openvpn-client (pid 5549) is running...