This translation is older than the original page and might be outdated. See what has changed.

OpenVPN PC端自动化脚本

在嵌入式设备生成秘钥可能比较费时。 可以在PC端通过脚本快速完成证书的创建。

在本地PC安装OpenVPN(生成证书的需要)后运行此脚本。 过程会提示设置client.ovpn的私钥密码。 然后您需要传输server.conf到路由器的/etc/openvpn目录,运行命令重启路由器的openvpn服务/etc/init.d/openvpn restart

注:

  • 以下脚本在MAC执行可能会报错(可能和Mac端的sed命令有关);
  • 以下脚本在CentOS7.9-2009,如果yum仓库默认安装低版本(低于2.5)的openvpn,会报错,由于脚本内的一个参数在老版本的openvpn内不存在;
  • CentOS7.9-2009,编译安装最新版本的openvpn2.5.6,脚本可顺利执行。
URL="https://openwrt.org/_export/code/docs/guide-user/services/vpn/openvpn/server"
cat << EOF > ovpn.sh
OVPN_DIR="openvpn"
OVPN_PKI="\${OVPN_DIR}/pki"
OVPN_PORT="1194"
OVPN_PROTO="udp"
OVPN_POOL="192.168.8.0 255.255.255.0"
OVPN_DNS="\${OVPN_POOL%.* *}.1"
OVPN_DOMAIN="lan"
FETCHIP_URL="http://v4.ipv6-test.com/api/myip.php"
OVPN_SERV="\$(wget -U "" -O - "\${FETCHIP_URL}")"
EASYRSA_URL="https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.6/EasyRSA-unix-v3.0.6.tgz"
if [ ! -f "EasyRSA.tgz" ]
then
wget -O EasyRSA.tgz "\${EASYRSA_URL}"
tar -z -x -f EasyRSA.tgz
fi
alias easyrsa="EasyRSA-v3.0.6/easyrsa"
$(wget -U "" -O - "${URL}?codeblock=1")
$(wget -U "" -O - "${URL}?codeblock=3" \
| sed -e "/^\/etc\/init\.d\//d")
ls \${OVPN_DIR}/*.conf
EOF
sh ovpn.sh
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2023/09/20 19:35
  • by vgaetera