惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
B
Blog
NISL@THU
NISL@THU
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
AWS News Blog
AWS News Blog
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
P
Palo Alto Networks Blog
I
Intezer
美团技术团队
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
H
Heimdal Security Blog
T
Troy Hunt's Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Forbes - Security
Forbes - Security
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
J
Java Code Geeks
The GitHub Blog
The GitHub Blog
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Cisco Blogs
S
SegmentFault 最新的问题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
AI
AI
WordPress大学
WordPress大学
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
Microsoft Azure Blog
Microsoft Azure Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
G
GRAHAM CLULEY
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
H
Hacker News: Front Page

puzzle9 blog

webdav - puzzle9 blog parser video tencent - puzzle9 blog wstunnel - puzzle9 blog rclone - puzzle9 blog debian 转换为 pve - puzzle9 blog nfs - puzzle9 blog caddy - puzzle9 blog webhookd 发布 - puzzle9 blog win 系统部署 by WinRM - puzzle9 blog hl7 初探 - puzzle9 blog realm 端口转发 - puzzle9 blog airflow - puzzle9 blog mysql 迁移到 mssql - puzzle9 blog 租房啊 - puzzle9 blog cr660x 路由器研究 - puzzle9 blog hs8145v 光猫研究 - puzzle9 blog dae 跨墙 - puzzle9 blog ZeroTier 打洞 🕊 - puzzle9 blog rathole 穿透 - puzzle9 blog
WireGuard 组网 - puzzle9 blog
2025-06-10 · via puzzle9 blog

要说 什么简单 省事

唯有 组网

就是有点爽 爱好红尘

定义

这是个基于 UDP 的异地组网工具

先放下官方的定义 对等体/节点/设备 Peer/Node/Device

诺 如下

名称虚拟ip自带网段
Isaac192.168.99.1/32
Alice192.168.99.2/32192.168.2.0/24
Bob192.168.99.3/32192.168.3.0/24
Carol192.168.99.4/32192.168.4.0/24
Dave192.168.99.5/32192.168.5.0/24

安装

  • net.ipv4.ip_forward = 1 添加到 /etc/sysctl.conf

debian

1
apt install wireguard-tools iptables

alpine

1
2
apk add wireguard-tools-wg-quick iptables wireguard-tools-openrc
rc-update add sysctl

修改 /etc/conf.d/iptablesIPFORWARDyes

配置

  • 公钥私钥采用 wg genkey | tee key.privatekey | wg pubkey > key.publickey 生成 每个人都是独立的
  • 配置文件在 /etc/wireguard 文件名就是网卡名 规则为 ^[a-zA-Z0-9_=+.-]{1,15}$
  • 以下配置文件有精简

AliceBob 一起玩 Alice 有公网

  • wg-quick up wg_ab_a

Alice /etc/wireguard/wg_ab_a.conf

1
2
3
4
5
6
7
8
[Interface]
Address = 192.168.99.2/24
ListenPort = 51820
PrivateKey = {Alice_PrivateKey}
[Peer]
# Name = Bob
PublicKey = {Bob_PublicKey}
AllowedIPs = 192.168.99.3/32, 192.168.3.0/24

Bob /etc/wireguard/wg_ab_a.conf

1
2
3
4
5
6
7
8
[Interface]
Address = 192.168.99.3/24
PrivateKey = {Bob_PrivateKey}
[Peer]
# Name = Alice
Endpoint = {Alice_ip}:51820
PublicKey = {Alice_PublicKey}
AllowedIPs = 192.168.99.2/32, 192.168.2.0/24

Alice Bob Carol 一起玩 Alice 有公网

  • wg-quick up wg_abc_a
  • Bob Carol 玩耍时通过 Alice 中转

Alice /etc/wireguard/wg_abc_a.conf

1
2
3
4
5
6
7
8
9
10
11
12
[Interface]
Address = 192.168.99.2/24
ListenPort = 51820
PrivateKey = {Alice_PrivateKey}
[Peer]
# Name = Bob
PublicKey = {Bob_PublicKey}
AllowedIPs = 192.168.99.3/32, 192.168.3.0/24
[Peer]
# Name = Carol
PublicKey = {Carol_PublicKey}
AllowedIPs = 192.168.99.4/32, 192.168.4.0/24

Bob /etc/wireguard/wg_abc_a.conf

1
2
3
4
5
6
7
8
[Interface]
Address = 192.168.99.3/24
PrivateKey = {Bob_PrivateKey}
[Peer]
# Name = Alice
Endpoint = {Alice_ip}:51820
PublicKey = {Alice_PublicKey}
AllowedIPs = 192.168.99.2/32, 192.168.3.0/24, 192.168.4.0/24

Carol /etc/wireguard/wg_abc_a.conf

1
2
3
4
5
6
7
8
[Interface]
Address = 192.168.99.4/24
PrivateKey = {Carol_PrivateKey}
[Peer]
# Name = Alice
Endpoint = {Alice_ip}:51820
PublicKey = {Alice_PublicKey}
AllowedIPs = 192.168.99.2/32, 192.168.2.0/24, 192.168.4.0/24

Alice Bob Carol 一起玩 都有公网

Q&A

AddressAllowedIPs 什么

站在 Alice 的角度

  • Address 是组网的ip地址 只有同个局域网才能一起玩
  • [Peer] 可以找谁一起玩
  • AllowedIPs 是路由 找他可以通过那个路出去
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[Interface]
# 我组了一个局域网
Address = 192.168.99.2/24
# 监听地址是这个
ListenPort = 51820
# 我的私钥
PrivateKey = {Alice_PrivateKey}
[Peer]
# Name = Bob
# 访问 192.168.3.0/24 网段时 去找 Bob
PublicKey = {Bob_PublicKey}
AllowedIPs = 192.168.99.3/32, 192.168.3.0/24
[Peer]
# Name = Carol
# 访问 192.168.4.0/24 网段时 去找 Carol
PublicKey = {Carol_PublicKey}
AllowedIPs = 192.168.99.4/32, 192.168.4.0/24

至于 WireGuard 怎么知道是 Bob 还是 Carol 来找自己了
那不是有 PublicKey 字段嘛 我推测是用它判断的

站在 Bob 的角度

1
2
3
4
5
6
7
8
9
10
11
12
[Interface]
# 我组了或者加入了一个局域网
Address = 192.168.99.3/24
# 我的私钥
PrivateKey = {Bob_PrivateKey}
[Peer]
# Name = Alice
Endpoint = {Alice_ip}:51820
PublicKey = {Alice_PublicKey}
AllowedIPs = 192.168.99.2/32, 192.168.3.0/24, 192.168.4.0/24
# 每25秒去敲下 Alice 的门 防止他忘记我
PersistentKeepalive = 25

可以通过 Endpoint 这个去找 Alice
我也想去找 Carol 玩 但是他和我都没得 公网
那我只能把相关的网段都给 Alice 让他去中转

参考地址