0aa8fe6
这次没有正文改动。
这是 vpn/OpenVPN 服务端与客户端.md 的改动记录。后台每次保存都会留一份快照,
这里显示的是快照之间的差异,不会混入其他文章的改动。
还没有后台修改记录。
下面是 Git 里的提交,可能包含其他文章的改动(因为一次提交会带上工作区所有变化)。
0aa8fe6
这次没有正文改动。
60178fc
@@ -0,0 +1,85 @@ +--- +tags: [OpenVPN, VPN, 证书] +order: 20 +--- + +# OpenVPN 服务端与客户端 + +## 场景 + +要给一批用户开远程接入,或者对端只支持 OpenVPN(TCP 443 也能走)。 + +## 前置条件 + +- 公网服务器,放行 UDP 1194(或 TCP 443) +- 有 easy-rsa 生成的 CA +- 规划 VPN 网段 + +## 配置 + +```bash +dnf install -y openvpn easy-rsa +make-cadir /etc/openvpn/easy-rsa +cd /etc/openvpn/easy-rsa + +./easyrsa init-pki +./easyrsa build-ca nopass +./easyrsa gen-req server nopass +./easyrsa sign-req server server +./easyrsa gen-dh +openvpn --genkey secret ta.key +``` + +服务端: + +```conf +# /etc/openvpn/server.conf +port 1194 +proto udp +dev tun +ca ca.crt +cert server.crt +key server.key +dh dh.pem +tls-auth ta.key 0 +server 10.9.0.0 255.255.255.0 +push "route 10.0.0.0 255.0.0.0" +push "dhcp-option DNS 10.0.0.2" +keepalive 10 120 +persist-key +persist-tun +status openvpn-status.log +verb 3 +``` + +```bash +systemctl enable --now openvpn@server +sysctl -w net.ipv4.ip_forward=1 +``` + +客户端 `.ovpn` 把 ca/cert/key/ta 拼进去即可。 + +## 验证 + +```bash +systemctl status openvpn@server +tail -f /var/log/openvpn.log +cat /etc/openvpn/openvpn-status.log +``` + +客户端连上后 `ip a` 会多出 `tun0`。 + +## 回滚 + +```bash +systemctl disable --now openvpn@server +``` + +## 坑 + +- **服务端和客户端 `dev` 不一致**(tun/tcp),连上但没流量。 +- `push "redirect-gateway def1"` 会把客户端全部流量拉走,可能断网。 +- 证书过期(默认 10 年倒还好),CA 换过要重发。 +- `tls-auth` 两边密钥不是同一个,握手失败。 +- 防火墙只放 UDP 1194,改 TCP 就通不了。 +- 客户端配置文件权限太松,私钥泄露。