Total Pageviews

Sunday, 2 July 2017

mac os下安装openvpn客户端并设置自启动

安装过程:
1.安装openvpn
sudo chown -R $(whoami) /usr/local

ALL_PROXY=socks5://localhost:1080 brew install openvpn 
 
2.安装tun/tap驱动
wget http://downloads.sourceforge.net/tuntaposx/tuntap_20150118.tar.gz  
tar zxvf tuntap_20150118.tar.gz  
然后在mac os桌面下,双击tuntap_20150118.pkg安装
3.准备client.conf文件,这个文件就是标准的client端文件
4.测试是否可以正常启动
/usr/local/opt/openvpn/sbin/openvpn --config /usr/local/etc/openvpn/ddky.conf
5.测试成功后在mac os编写plist文件
vi /Library/LaunchDaemons/net.openvpn.plist  
<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"  
"http://www.apple.com/DTDs/PropertyList-1.0.dtd";>
<plist version="1.0">

<dict>  
        <key>Label</key>
        <string>net.openvpn</string>
        <key>KeepAlive</key>
        <dict>
                <key>NetworkState</key>
                <true/>
        </dict>
        <key>Program</key>
        <string>/usr/local/opt/openvpn/sbin/openvpn</string>
        <key>ProgramArguments</key>
        <array>
                <string>openvpn</string>
                <string>--config</string>
                <string>/usr/local/etc/openvpn/client.conf</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>TimeOut</key>
        <integer>90</integer>
        <key>WorkingDirectory</key>
        <string>/usr/local/etc/openvpn</string>
</dict>  
</plist>  
6.然后运行
sudo chown root:wheel /Library/LaunchDaemon/net.openvpn.plist

sudo launchctl load /Library/LaunchDaemon/net.openvpn.plist  
有用的命令:
sudo launchctl load /Library/LaunchDaemon/net.openvpn.plist  
sudo launchctl unload /Library/LaunchDaemon/net.openvpn.plist  
sudo launchctl start /Library/LaunchDaemon/net.openvpn  
sudo launchctl stop /Library/LaunchDaemon/net.openvpn  

No comments:

Post a Comment