赞
踩
OpenVPN是一个开源的虚拟私人网络(VPN)软件包,可以用于创建加密的网络通道。它使用OpenSSL库中的SSL/TLS协议来保证数据的安全性和完整性。OpenVPN支持多种身份验证方式,包括共享密钥、电子证书、或者用户名/密码。OpenVPN可以运行在多种操作系统上,如Windows、Linux、Mac OS、Android等
主机名 | 系统 | 网络 | 备注 |
---|---|---|---|
vpnserver | ubuntu22.04 | ens33:192.168.46.11/24 ens37:192.168.10.10/24 | OpenVPN服务器 |
nw1 | ubuntu22.04 | ens33:192.168.10.12/24 | 内网机器,nginx |
Windows client | Windows 11 | 192.168.2.2/24 | 客户端 |
GitHub链接:https://github.com/OpenVPN/openvpn/releases
我选择的版本为:v2.6.8
GitHub链接:https://github.com/OpenVPN/easy-rsa/releases
tar -xvf EasyRSA-3.1.7.tgz
tar -xvf openvpn-2.6.8.tar.gz
# 安装编译工具及编译环境(根据实际报错信息安装对应的编译环境)
apt -y install gcc make libnl-genl-3-dev libnl-3-dev libpkgconf-dev pkg-config libcap-ng-dev openssl libssl-dev liblz4-dev liblzo2-dev libpam0g-dev
cd openvpn-2.6.8/
./configure
make
make install
mkdir -p /usr/local/openvpn
cp -r EasyRSA-3.1.7/ /usr/local/openvpn/easyrsa
cd /usr/local/openvpn/easyrsa
cp vars.example vars
vim vars
# 把注释取消并修改
set_var EASYRSA_REQ_COUNTRY "CN"
set_var EASYRSA_REQ_PROVINCE "BeiJing"
set_var EASYRSA_REQ_CITY "BeiJing"
set_var EASYRSA_REQ_ORG "BeiJing co"
set_var EASYRSA_REQ_EMAIL "test@gmail.com"
set_var EASYRSA_REQ_OU "BeiJing"
./easyrsa init-pki
./easyrsa build-ca nopass
./easyrsa build-server-full vpnserver nopass
./easyrsa build-client-full vpnclient nopass
./easyrsa gen-dh
mkdir -p /usr/local/openvpn/keys
cp /usr/local/openvpn/easyrsa/pki/{ca.crt,dh.pem} /usr/local/openvpn/
cp /usr/local/openvpn/easyrsa/pki/private/{vpnclient.key,vpnserver.key} /usr/local/openvpn/keys
cp /usr/local/openvpn/easyrsa/pki/issued/{vpnclient.crt,vpnserver.crt} /usr/local/openvpn/keys
openvpn --genkey secret /usr/local/openvpn/keys/ta.key
cp openvpn-2.6.8/sample/sample-config-files/server.conf /usr/local/openvpn
vim /usr/local/openvpn/server.conf
port 1194 # 端口号
proto udp # 连接协议
dev tun # 模拟三层VPN
ca /usr/local/openvpn/ca.crt # 调用ca证书
cert /usr/local/openvpn/keys/vpnserver.crt # 调用服务证书文件
key /usr/local/openvpn/keys/vpnserver.key # 调用服务器私钥文件
dh /usr/local/openvpn/dh.pem # 调用Diffie Hellman文件
topology subnet # 定义网络拓扑为子网
server 10.8.0.0 255.255.255.0 # 设置客户端可获取的IP地址池
ifconfig-pool-persist ipp.txt # 客户端IP虚拟IP地址记录文件
push "route 192.168.10.0 255.255.255.0" # 客户端获取的内网信息
push "dhcp-option DNS 114.114.114.114" # 客户端获取的DNS信息
tls-auth /usr/local/openvpn/keys/ta.key 0 # 调用密钥
cipher AES-256-GCM # 网络通信加密算法
vim /usr/lib/systemd/system/openvpn-server.service
[Unit]
Description=OpenVPN server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/sbin/openvpn --daemon --config /usr/local/openvpn/server.conf
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=3
[Install]
WantedBy=multi-user.target
vim /etc/sysctl.d/10-net.conf
net.ipv4.ip_forward = 1
sysctl -p /etc/sysctl.d/10-net.conf
官方链接:https://openvpn.net/community-downloads/
下载安装即可
mkdir -p /usr/local/openvpn/client
cp openvpn-2.6.8/sample/sample-config-files/client.conf /usr/local/openvpn/client/client.ovpn
vim /usr/local/openvpn/client/client.ovpn
client
dev tun
proto udp
remote 192.168.46.11 1194
ca ca.crt
cert vpnclient.crt
key vpnclient.key
tls-auth ta.key 1
cipher AES-256-GCM
cp /usr/local/openvpn/ca.crt /usr/local/openvpn/client/
cp /usr/local/openvpn/keys/{vpnclient.crt,vpnclient.key,ta.key} /usr/local/openvpn/client/
cd /usr/local/openvpn/client
zip client.zip ./*
这次修改是要把那些证书文件修改为绝对路径(根据你自己的路径修改)
同时可以访问OpenVPN服务器的内网地址
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。