视频连接

这期节目向大家介绍一下如何使用OpenWrt上的wireguard服务。wireguard服务搭建成功后(通过简单的路由设置),我们可以在外网通过客户端连接到家庭网络,达到任意访问家里局域网中的设备的目的。 这种方法同样也适用于公司网络以及任何你想在外网连入的网络。相比一些商业服务(比如花生壳,zerotier)此方案更简洁高效(基于Linux内核模块),代码完全开源,安全有保障,配置也不算复杂。 如果有公网IP,可以通过DDNS直连,如果没有公网IP可以通过FRP端口转发。本期节目少量代码,适合小白入门。

相关资源

动态域名(DDNS)使用教程

以下资料来源于互联网
cloudflare动态域名
阿里云动态域名

eSir精品小包固件下载地址(感谢esir的辛勤付出)

eSir精品小包固件

OpenWrt安装WireGuard命令(eSir精品小包已集成WireGuard,无需安装)

1
2
3
opkg update
opkg install luci-proto-wireguard luci-app-wireguard wireguard kmod-wireguard wireguard-tools
reboot

WireGuard密钥生成

1.设置文件权限

umask 077

2.生成服务端Privatekey和Pubkey

wg genkey | tee sprivatekey | wg pubkey > spublickey

3.生成客户端端Privatekey和Pubkey

wg genkey | tee cprivatekey | wg pubkey > cpublickey

4.生成预共享密钥PresharedKey

wg genpsk > sharekey

客户端模板文件test.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[Interface]
Address = 192.168.100.2
PrivateKey = cprivatekey文件内容 
DNS = 路由器IP
[Peer]
PublicKey = spublickey文件内容  
AllowedIPs = 0.0.0.0/0
# 如果启用下面这行代码,表示只有192.168.2.0/24, 192.168.100.0/24这两个子网的IP走WireGuard
# AllowedIPs = 192.168.2.0/24, 192.168.100.0/24
Endpoint = 公网IP:端口号
PersistentKeepalive = 25

真实的test.conf的例子

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
[Interface]
Address = 192.168.100.2
PrivateKey = qB5rRYDTF7b7iEQSZ91ixQ7XAvuiY2aXJtg3aasz01Y=
DNS = 192.168.2.1
[Peer]
PublicKey = SfBTCxkXG2P5QMin1CScP5eyaOD7RG9v2OSWlJrcWxY=
AllowedIPs = 0.0.0.0/0
PresharedKey = ENLutSSKXVdHBokmrFu+gOq/JCATLbX+a7SmeXNpvTQ=
Endpoint = yourhome.demo.com:23456
PersistentKeepalive = 25

WireGuard客户端安装地址

https://www.wireguard.com/install/
https://wws.lanzoui.com/iCRwqqy0neh 解压密码:www.126126.xyz


网飞合租:https://d.126126.xyz/5
自用机场:https://d.126126.xyz/3
youtube:https://www.youtube.com/c/ericwang618
哔哩哔哩:https://space.bilibili.com/221010336
Telegram:https://t.me/first_sunlight
个人网站:https://www.126126.xyz
合作邮箱:fs104300@outlook.com