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

推荐订阅源

T
Tailwind CSS Blog
C
CERT Recently Published Vulnerability Notes
P
Proofpoint News Feed
Vercel News
Vercel News
博客园 - 三生石上(FineUI控件)
IT之家
IT之家
Help Net Security
Help Net Security
月光博客
月光博客
N
News and Events Feed by Topic
Cloudbric
Cloudbric
博客园 - 司徒正美
L
LangChain Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tenable Blog
The Register - Security
The Register - Security
The Hacker News
The Hacker News
I
InfoQ
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
Schneier on Security
Schneier on Security
WordPress大学
WordPress大学
小众软件
小众软件
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
宝玉的分享
宝玉的分享
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
K
Kaspersky official blog
L
LINUX DO - 热门话题
N
News | PayPal Newsroom
F
Fortinet All Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Security @ Cisco Blogs
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
H
Help Net Security
Google Online Security Blog
Google Online Security Blog
S
Schneier on Security
C
Cisco Blogs
N
News and Events Feed by Topic
V2EX - 技术
V2EX - 技术
Latest news
Latest news
PCI Perspectives
PCI Perspectives
T
The Blog of Author Tim Ferriss
P
Palo Alto Networks Blog
T
Tor Project blog
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Webroot Blog
Webroot Blog
Attack and Defense Labs
Attack and Defense Labs
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

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 让他去中转

参考地址