fedora19/opensuse13.1 配置openvpn client

Date: 20140207
Auth: Jin

1.install

# yum -y install openvpn

#zypper install openvpn

 

2.copy user key 

# cp -r /run/media/diege/新加卷/config /etc/openvpn/

 

3.start

# openvpn --config /etc/openvpn/config/zj.ovpn
Options error: --ca fails with 'zj/ca.crt': No such file or directory
Options error: --cert fails with 'zj/diege.crt': No such file or directory
Options error: --key fails with 'zj/diege.key': No such file or directory
Options error: Please correct these errors.
Use --help for more information.

[root@172-1-1-89 openvpn]# cd config/
[root@172-1-1-89 config]# pwd
/etc/openvpn/config

4.check

# ifconfig tun0
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 192.167.0.22 netmask 255.255.255.255 destination 192.167.0.21
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC)
RX packets 3 bytes 252 (252.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3 bytes 252 (252.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.8.1.1 0.0.0.0 UG 0 0 0 wlp3s0
10.0.0.0 192.167.0.21 255.255.255.0 UG 0 0 0 tun0
10.0.1.0 192.167.0.21 255.255.255.0 UG 0 0 0 tun0
10.10.0.0 192.167.0.21 255.255.255.0 UG 0 0 0 tun0

# ping 10.0.0.221
PING 10.0.0.221 (10.0.0.221) 56(84) bytes of data.
64 bytes from 10.0.0.221: icmp_seq=1 ttl=63 time=30.0 ms
64 bytes from 10.0.0.221: icmp_seq=2 ttl=63 time=31.1 ms

5.write openvpn client shell

vim openvpn-client.sh

 

#!/bin/env bash
### Date: 20140207
### Auth: Jin

PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

pidfile='/var/run/openvpn/client.pid'
configdir='/etc/openvpn/config'

function status() {
    if [ -f ${pidfile} ];then
        pid=$(cat ${pidfile})
        echo "Openvpn Client is running with pid: ${pid}!"
    else
        echo 'Openvpn Client is not running!'
    fi
}

case $1 in
   startSTART)
    if [ $# -eq 2 ];then
        cd ${configdir}
        if [ $2 == 'zj' -o $2 == 'ks' ];then
            if [ -f ${pidfile} ];then
                 status
            else
                echo "Now start $2 openvpn client."
                nohup openvpn --config ${configdir}/$2.ovpn --writepid ${pidfile} &
                sleep 3
                status
            fi
        else
            echo 'Please choose zj or ks!'
        fi
    else
        echo 'Please give two parameters! Second parameter choose zj or ks!'
    fi
    ;;
   stopSTOP)
    echo 'Now stop openvpn client.'
    if [ -f ${pidfile} ];then
        kill `cat ${pidfile}`
        if [ $? -eq 0 ];then
            rm -f ${pidfile}
            sleep 3
            status
        else
            echo 'Stop openvpn client failed!'
        fi
    else
        echo "PID File: ${pidfile} not exist!"
    fi
       ;;
   statusSTATUS)
    status
       ;;
   *)
    echo "usage:$0 start (zjks)stopstatus"
   esac

 

 

更多相关文章
一周排行