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

推荐订阅源

C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Tor Project blog
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Latest news
Latest news
L
LINUX DO - 热门话题
罗磊的独立博客
T
Tenable Blog
The Hacker News
The Hacker News
美团技术团队
N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
博客园 - 司徒正美
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
云风的 BLOG
云风的 BLOG
S
Secure Thoughts
Cloudbric
Cloudbric
S
Security @ Cisco Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
U
Unit 42
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
爱范儿
爱范儿
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
P
Palo Alto Networks Blog
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
F
Full Disclosure
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security Affairs
Project Zero
Project Zero

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

参考地址