0aa8fe6
这次没有正文改动。
这是 vpn/WireGuard 配置.md 的改动记录。后台每次保存都会留一份快照,
这里显示的是快照之间的差异,不会混入其他文章的改动。
还没有后台修改记录。
下面是 Git 里的提交,可能包含其他文章的改动(因为一次提交会带上工作区所有变化)。
0aa8fe6
这次没有正文改动。
60178fc
@@ -0,0 +1,84 @@ +--- +tags: [WireGuard, VPN, 远程接入] +order: 10 +--- + +# WireGuard 配置 + +## 场景 + +要让几台在外面的机器(或自己的笔记本)安全地访问内网,比 OpenVPN 轻、配置短。 + +## 前置条件 + +- 一台有公网 IP 的服务器做服务端 +- 服务端能开 UDP 端口(默认 51820) +- 规划 VPN 网段(比如 10.8.0.0/24),别和内网冲突 + +## 配置 + +```bash +dnf install -y wireguard-tools + +# 生成密钥 +cd /etc/wireguard +wg genkey | tee server.key | wg pubkey > server.pub +chmod 600 server.key + +cat >/etc/wireguard/wg0.conf <<'EOF' +[Interface] +Address = 10.8.0.1/24 +ListenPort = 51820 +PrivateKey = <server.key 内容> +PostUp = firewall-cmd --add-port=51820/udp +PostDown = firewall-cmd --remove-port=51820/udp + +[Peer] +PublicKey = <客户端公钥> +AllowedIPs = 10.8.0.2/32 +EOF + +systemctl enable --now wg-quick@wg0 +``` + +客户端: + +```ini +[Interface] +Address = 10.8.0.2/24 +PrivateKey = <client.key> +DNS = 10.0.0.2 + +[Peer] +PublicKey = <server.pub> +Endpoint = vpn.example.com:51820 +AllowedIPs = 10.0.0.0/8, 192.168.0.0/16 +PersistentKeepalive = 25 +``` + +## 验证 + +```bash +wg show +``` + +`latest handshake` 有时间、`transfer` 有流量,说明通了。 + +```bash +ping 10.8.0.1 +``` + +## 回滚 + +```bash +systemctl disable --now wg-quick@wg0 +``` + +## 坑 + +- **UDP 被防火墙挡了**,`wg show` 一直没握手。 +- 客户端 `AllowedIPs` 写 `0.0.0.0/0` 会抢默认路由,导致 SSH 断线,先确认。 +- 服务端没开 `net.ipv4.ip_forward=1`,客户端之间和内网都通不了。 +- 需要 NAT 时在 `PostUp` 里加 masquerade。 +- 网段和公司内网冲突,连上后访问内网反而失败。 +- 密钥泄露只能换一对,没有吊销列表。