认识
OpenVPN 是一个开源的 VPN 解决方案,基于 SSL/TLS 协议实现加密通信,支持 TCP 和 UDP 传输。它通过虚拟网卡(TUN/TAP)建立隧道,提供灵活的配置和高安全性。OpenVPN 是一个开源的虚拟专用网络(VPN)解决方案,用于创建安全的点对点或站点到站点的连接。它使用 SSL/TLS 协议进行加密,支持多种认证方式,并能在大多数操作系统上运行,包括 Windows、macOS、Linux、Android 和 iOS。
注意,SSL VPN 是另外一种基于 HTTPS(SSL/TLS)的 VPN 技术。
文档:https://openvpn.net/community-resources/
仓库
- https://github.com/OpenVPN/openvpn
- Subversion Repository | https://openvpn.net/community-resources/subversion-repository/
组成
OpenVPN 在 OSI 模型的 传输层(第4层) 或 网络层(第3层) 上运行,通常使用:
UDP 1194 端口(默认)。
也可配置为 TCP 模式(适合严格防火墙环境,但效率稍低)。
协议:使用 SSL/TLS 进行密钥交换和身份验证,支持 AES 等强加密算法。
两种主要模式:
- TUN(Layer 3)
- 模拟网络层设备,传输 IP 数据包(类似路由器)。
- 适用于路由 VPN 流量(如访问公司内网)。
- TAP(Layer 2)
- 模拟数据链路层设备,传输以太网帧(类似交换机)。
- 适用于桥接模式(如远程设备加入本地局域网)。
独有协议
Most SSL-based VPNs use the same network protocol as is used for secure website (HTTPS), while OpenVPN uses a custom format for encrypting and signing data traffic. This is the main reason why OpenVPN is listed as a separate VPN category.
OpenVPN is often called an SSL-based VPN, as it uses the SSL/TLS protocol to secure the connection. However, OpenVPN also uses HMAC in combination with a digest (or hashing) algorithm for ensuring the integrity of the packets delivered. It can be configured to use pre-shared keys as well as X.509 certificates. These features are not typically offered by other SSL-based VPNs.
The OpenVPN protocol is not defined in an RFC standard, but the protocol is publicly available because OpenVPN is a piece of open source software.
OpenVPN Protocol | https://openvpn.net/community-resources/openvpn-protocol/
Protocol Compatibility | https://openvpn.net/community-resources/protocol-compatibility/
构建
—— 该部分将记录“构建”OpenVPN 服务的方法,旨在获得 OpenVPN 服务,但是并不涉及具体的使用及配置,更不涉及具体场景的应用案例。
针对不同的应用场景,OpenVPN Inc. 提供多种解决方案。本质上,该类解决方案都能提供最基本基本的 OpenVPN 功能,差别在于商业版能够提供更多高级功能(例如,维护管理、高级特性、……)。
OpenVPN open-source projects
https://openvpn.net/community/
OpenVPN 2
- 主要的开源版本,为所有主流平台提供完整的 Client/Server 解决方案。非常适合希望完全控制并灵活设置 VPN 的用户。
OpenVPN 3
- 认识:是个支持多线程的客户端库,用于 OpenVPN Connect 和 CloudConnexa 产品。
- 官网:https://openvpn.github.io/openvpn3/
- 文档:https://openvpn.net/community-resources/openvpn3-core-library-documentation/
- 仓库:https://github.com/OpenVPN/openvpn3
- OpenVPN 3 is a C++ class library that implements the functionality of an OpenVPN client, and is protocol-compatible with the OpenVPN 2.x branch.
- 根据官方文档,现阶段 04/14/2025 OpenVPN 3 并未实现 Server 功能,所以提供 OpenVPN 服务需要部署 OpenVPN 2 版本。
OpenVPN 3 Linux Client
- 基于 OpenVPN 3 并集成 dbus 的下一代 Linux Client 程序。
快速开始 | OpenVPN Quickstart
服务安装 | Installing OpenVPN
- https://openvpn.net/community-resources/installing-openvpn/
- The standard INSTALL file included in the source distribution | https://openvpn.net/community-resources/the-standard-install-file-included-in-the-source-distribution/
命令行选项 | Reference manual for OpenVPN 2.6
服务运行、开机自启动
- Configuring OpenVPN to run automatically on system startup | https://openvpn.net/community-resources/configuring-openvpn-to-run-automatically-on-system-startup/
- Running OpenVPN as a Windows Service | https://openvpn.net/community-resources/running-openvpn-as-a-windows-service/
- Running OpenVPN from a console window | https://openvpn.net/community-resources/running-openvpn-from-a-console-window/
管理接口 | Management Interface | 通过 a TCP or unix domain socket 来管理 OpenVPN 服务
https://openvpn.net/community-resources/management-interface/
进程管理 | Controlling a running OpenVPN process
高可用、故障转移 | Implementing a load-balancing/failover configuration
我们的部署方案:
- 在 pfSense 中,其内置 OpenVPN 组件,所以我们直接使用,并借助 pfSense 提供的 FRR 来部署功能更加丰富的网络。
Access Server
https://openvpn.net/access-server/
- 自托管 VPN 解决方案,让我们在硬件或云基础架构上运行自己的服务器。
- 包含基于 Web 的管理界面
根据我们的理解,Access Server 应该是 OpenVPN 的商业版,其中附带很多高级功能,比如 Web UI、……
CloudConnexa
https://openvpn.net/cloud-vpn/
- 用途:其为 OpenVPN Inc. 托管的服务,无需维护基础设施。
OpenVPN Connect
- 用途:客户端
性质
跨平台:Windows、macOS、Linux、Android、iOS,需要安装客户端软件(如 OpenVPN GUI、……)。
认证方式:证书认证(推荐)。用户名/密码认证。双因素认证(2FA)。可通过插件扩展功能(如 LDAP、Radius 认证)。
开源免费:代码公开,可自由使用和修改。代码公开,安全性经过广泛审查。
安全性强:支持现代加密标准。默认使用 OpenSSL 库,支持 AES、RSA、SHA 等加密算法。
灵活配置:
支持 TCP/UDP 协议。
可穿透 NAT 和防火墙。
支持动态 IP 和 DHCP。
可扩展性:
支持 IPv4 和 IPv6。
灵活性:
可配置为站点到站点(Site-to-Site)或远程访问(Remote Access)模式。
穿透防火墙:通常使用 UDP 端口 1194(可自定义),能绕过大多数防火墙限制。
优点
高度可定制,适合复杂网络环境。
社区支持丰富,文档齐全。
缺点
配置稍复杂(尤其是证书管理)。
Static Key
Static Key Mini-HOWTO | https://openvpn.net/community-resources/static-key-mini-howto/
必须定义 CA 信息
Options error: You must define CA file (–ca) or CA path (–capath)
Routing and Bridging
根据官方文档的描述,其建议:
- 选择 Layer 3 即 Routing 方式,原因存在优势,例如、更高效、更容易进行配置管理、更容易进行访问控制、……
- 除非某些特殊需求,则建议使用 Layer 2 Bridging 方式。
更多细节,参考文档:https://openvpn.net/community-resources/determining-whether-to-use-a-routed-or-bridged-vpn/
Ethernet Bridging | https://openvpn.net/community-resources/ethernet-bridging/
Notes — Ethernet bridging, Windows client, Linux Server | https://openvpn.net/community-resources/notes-ethernet-bridging-windows-client-linux-server/
Notes — Ethernet bridging, with the bridge occurring on the Windows side. | https://openvpn.net/community-resources/notes-ethernet-bridging-with-the-bridge-occurring-on-the-windows-side/
路由 | Route
Expanding the scope of the VPN to include additional machines on either the client or server subnet. | https://openvpn.net/community-resources/expanding-the-scope-of-the-vpn-to-include-additional-machines-on-either-the-client-or-server-subnet/
Setting up routing | https://openvpn.net/community-resources/setting-up-routing/
IP and DHCP
Notes — Setting TAP-Windows address/subnet automatically via DHCP
https://openvpn.net/community-resources/notes-setting-tap-windows-address-subnet-automatically-via-dhcp/
Numbering private subnets | 地址规划建议
https://openvpn.net/community-resources/numbering-private-subnets/
Pushing DHCP options to clients
https://openvpn.net/community-resources/pushing-dhcp-options-to-clients/
安全 | Security
Hardening OpenVPN Security | https://openvpn.net/community-resources/hardening-openvpn-security/
Important Note on possible “Man-in-the-Middle” attack if clients do not verify the certificate of the server they are connecting to. | https://openvpn.net/community-resources/important-note-on-possible-man-in-the-middle-attack-if-clients-do-not-verify-the-certificate-of-the-server-they-are-connecting-to/
OpenVPN cryptographic layer | https://openvpn.net/community-resources/openvpn-cryptographic-layer/
Revoking Certificates | https://openvpn.net/community-resources/revoking-certificates/
RSA Key Management | https://openvpn.net/community-resources/rsa-key-management/
Setting up your own Certificate Authority (CA) | https://openvpn.net/community-resources/setting-up-your-own-certificate-authority-ca/
建议
- 使用证书认证(而非仅密码)。
- 禁用弱加密算法(如 DES、RC4)。
- 启用 TLS-auth(防止 DDoS 攻击)。
- 定期更新密钥和证书。
- 限制客户端权限(如 –client-to-client 控制是否允许客户端互通)。
认证 | Authentication Methods
Using alternative authentication methods | https://openvpn.net/community-resources/using-alternative-authentication-methods/
通过 HTTP Proxy 连接
DeepSeek / 介绍通过 HTTP Proxy 连接 OpenVPN 技术
OpenVPN 默认使用 TCP/UDP 协议,直接连接服务器。但在,某些网络环境下(例如,公司/学校防火墙限制、……),直接连接可能被阻断。
通过 HTTP Proxy 中转流量,可以将 OpenVPN 的通信封装在 HTTP 协议内,伪装成普通网页流量,从而绕过限制。
Connecting to an OpenVPN server via an HTTP proxy.
https://openvpn.net/community-resources/connecting-to-an-openvpn-server-via-an-http-proxy/
on Windows notes
https://openvpn.net/community-resources/openvpn-on-windows-notes/
应用
远程办公:安全访问公司内部资源。企业远程办公,接入企业网络。
隐私保护:加密互联网流量,防止 ISP 或黑客监控。个人隐私保护(例如,连接公共 Wi-Fi 时加密流量、……)。
绕过审查:突破地域限制访问被屏蔽的网站。
游戏联机:建立虚拟局域网(LAN)进行低延迟联机。
跨地域站点互联。注,针对企业网络间的站点互联,建议考虑其他 VPN 技术。
我们未采用 OpenVPN 服务,原因在于:
- 企业员工接入:OpenVPN 并非各主流操作系统提供的内置 VPN 接入方式;
- 数据中心组网:OpenVPN 很少在企业组网中使用,至少目前(04/14/2025)在部分企业级网络设备中暂时未看到 OpenVPN 身影;
- 网络协议标准:虽然它构建在 TLS 之上,但 OpenVPN 严格上将并不属于 SSL VPN,它使用自己的协议;
针对用户类型,控制其能访问的资源 | Configuring client-specific rules and access policies
https://openvpn.net/community-resources/configuring-client-specific-rules-and-access-policies/
在 Layer 3 Networking 中,配置并访问 Samba 服务的方法 | Connecting to a Samba share over OpenVPN
https://openvpn.net/community-resources/connecting-to-a-samba-share-over-openvpn/
改进
Mailing Lists | https://openvpn.net/community-resources/mailing-lists/
可移植性 | Porting Notes
https://openvpn.net/community-resources/porting-notes/
参考
VPN 三种协议 PPTP、L2TP、OpenVPN 对比
OpenVPN 项目首页
基于 Docker 搭建企业级 Openvpn 专有网络
vpn – OpenVPN Client Authentication without Certificates – Server Fault