vyos上配置wireguard (IPV4)
1. 生成 WireGuard 密钥
wg genkey | tee privatekey | wg pubkey > publickey• privatekey 文件中存储 私钥
• publickey 文件中存储 公钥
然后使用:
cat privatekey把私钥填入 第一步 的 <服务器私钥> 位置。
配置wireguard:
set interfaces wireguard wg0 address '10.20.30.1/24'
set interfaces wireguard wg0 port '11133'
set interfaces wireguard wg0 private-key 'private-key'
set interfaces wireguard wg0 peer iphone allowed-ips '10.20.30.2/32'
set interfaces wireguard wg0 peer iphone public-key 'public-key'
set interfaces wireguard wg0 peer iphone preshared-key 'preshared-key'上面这是添加过peer的。
如果让wg科学,下面接着操作:
添加组:
set firewall group network-group LAN-v4 network '10.20.20.0/24' # 内网段
set firewall group network-group LAN-v4 network '10.20.23.0/24' # wg网段
set firewall group ipv6-network-group LAN-v6 network 'fd88::/64'
设置策略路由:
举例: 让wg0的流量走100号路由表, 100号路由表是sb的路由表
set policy route WG0-to-SB interface 'wg0'
set policy route WG0-to-SB rule 10 destination group network-group '!LAN-v4'
set policy route WG0-to-SB rule 10 set table '100'
# 这下面三条仅供参考,添加后电报容易断连。
set policy route6 WG0-to-SB interface 'wg0'
set policy route6 WG0-to-SB rule 10 destination group network-group '!LAN-v6'
set policy route6 WG0-to-SB rule 10 set table '106'
#路由表(之前添加过就不要重复添加)
set protocols static table 100 route 0.0.0.0/0 next-hop 10.20.20.9
or
set protocols static table 100 route 0.0.0.0/0 next-hop 172.23.0.99
set protocols static table 100 route 0.0.0.0/0 next-hop 192.168.100.9
set protocols static table 106 route6 ::/0 next-hop fd88::9999
-----
Happy Routing!2.vyos上配置wireguard (IPV4)预共享密钥
配置 WireGuard 的 预共享密钥(Preshared Key,简称 PSK),可以为现有的公私钥握手再加一层加密,提升安全性。
🧩 PSK 是什么? 预共享密钥是在通信双方私下共享的额外密钥,用作对称加密(混淆 DH 密钥协商结果),提高抵抗量子计算破解的能力
✅ 如何生成 PSK 在 VyOS 或客户端(都可以)执行:
wg genpsk > psk.key查看内容:
cat psk.key会输出一串 Base64 编码的密钥,比如:
zT4XEDXe9qJpKRgqz0VjdRm2Vu+I+ZYoY7vI99aAv0Q=🧩 在 VyOS 中添加 PSK 假设你已有如下 WireGuard 配置:
set interfaces wireguard wg0 address '10.20.30.1/24'
set interfaces wireguard wg0 port '51820'
set interfaces wireguard wg0 peer iphone public-key 'xxx...='加入 PSK 的命令如下:
set interfaces wireguard wg0 peer iphone preshared-key 'zT4XEDXe9qJpKRgqz0VjdRm2Vu+I+ZYoY7vI99aAv00=