二言目 - OpenVpn
type: channel
link: https://blog.piemoe.com/tag/OpenVpn/
items: Openvpn搭建及使用方法

Openvpn搭建及使用方法
type: item
date: 2023-03-02T10:23:00+08:00
description: Openvpn搭建及使用方法前置操作echo 1 > /proc/sys/net/ipv4/ip_forward sysctl -p /etc/sysctl.conf搭建步骤拉取镜像docker pull kylemanna/openvpn创建全局变量OVPN_DATA="/data/openvpn" mkdir $OVPN_DATA配置公网ipIP="xxx.xxx.xxx.xxx"初始化将保存配置文件和证书的容器。容器将提示输入密码以保护新生成的证书颁发机构使用的私钥tcp：docker run -v ${OVPN_DATA}:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u tcp://${IP}udp：docker run -v ${OVPN_DATA}:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://${IP}密钥配置docker run -v ${OVPN_DATA}:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki例子Enter PEM pass phrase: 输入123456（你是看不见的） Verifying - Enter PEM pass phrase: 输入123456（你是看不见的） Common Name (eg: your user, host, or server name) [Easy-RSA CA]:回车一下 Enter pass phrase for /etc/openvpn/pki/private/ca.key:输入123456启动打开VPN服务器进程tcp：docker run --name openvpn -v ${OVPN_DATA}:/etc/openvpn -d -p 1194:1194 --cap-add=NET_ADMIN --name openvpn kylemanna/openvpnudp：docker run --name openvpn -v ${OVPN_DATA}:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN --name openvpn kylemanna/openvpn生成不带密码的客户端证书docker run -v ${OVPN_DATA}:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass检索带有嵌入式证书的客户端配置docker run -v ${OVPN_DATA}:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient example > example.ovpn客户端下载Community Downloads | OpenVPNOpenVPN-2.5.7-I602-amd64.msi删除docker run -v ${OVPN_DATA}:/etc/openvpn --rm -it kylemanna/openvpn easyrsa revoke $DNAME docker run -v ${OVPN_DATA}:/etc/openvpn --rm -it kylemanna/openvpn easyrsa gen-crl docker run -v ${OVPN_DATA}:/etc/openvpn --rm -it kylemanna/openvpn rm -f /etc/openvpn/pki/reqs/"$DNAME".req docker run -v ${OVPN_DATA}:/etc/openvpn --rm -it kylemanna/openvpn rm -f /etc/openvpn/pki/private/"$DNAME".key docker run -v ${OVPN_DATA}:/etc/openvpn --rm -it kylemanna/openvpn rm -f /etc/openvpn/pki/issued/"$DNAME".crt