使用 Netmaker 异地组网

什么是Netmaker?

Netmaker 是一个开源的、基于 [[WireGuard]] 的网络(overlay network) 控制工具,可以非常快速的用来组建 WireGuard 网络。

如果你有两台连接互联网的设备,那么 Netmaker 可以组建一个安全的网络,并打通一个安全的隧道提供给两台机器通信。而如果你有数千台机器分布在不同的地区,不同的数据中心,不同的网络中,那么 Netmaker 也可以组建一个网络来提供给这些不同的节点通信。

Netmaker使用 C/S 架构,方便管理:

  • Netmaker:管理端,用于下发配置文件等信息
  • Netclient:节点(可以为你的任何设备:Windows PC,Linux等)

虽然为C/S架构,但节点之间还是Full Mesh的状态,Netmaker挂掉了也不影响组网状态。

Netmaker 独特的Relay和Ingress 功能,这是ZeroTier、Tinc等不具备的。我们可以随时将可公开访问的节点(如 Netmaker 服务器)指定为中继,并告诉它应该中继哪些节点。

Get Start

计划组网的设备有这些:

  • PC * 1
  • 家里的OpenWRT路由器 * 1
  • 位于 DO-SFO3 的 VPS * 1
  • JP BBTEC VPS * 1 (计划用于Relay节点)

构建Netmaker管理端

首先搭建Netmaker管理端,我选择放在 DO-SFO3 上。

根据官方文档一步一步走就行了:Quick Install — Netmaker 0.14.5 documentation

配置DNS:

如果你也是使用Cloudflare,可以像我这样直接配置泛域名解析

安装必要软件:

1
2
apt-get update -y
apt-get install -y docker.io docker-compose wireguard

放行防火墙:

1
2
sudo ufw allow proto tcp from any to any port 443 && sudo ufw allow 51821:51830/udp
iptables --policy FORWARD ACCEPT

安装Netmaker:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ip route get 1 | sed -n 's/^.*src \([0-9.]*\) .*$/\1/p'

wget -O docker-compose.yml https://raw.githubusercontent.com/gravitl/netmaker/master/compose/docker-compose.yml
# 记得修改以下的信息为自己的域名,ip
sed -i 's/NETMAKER_BASE_DOMAIN/<your base domain>/g' docker-compose.yml
sed -i 's/SERVER_PUBLIC_IP/<your server ip>/g' docker-compose.yml
sed -i 's/YOUR_EMAIL/<your email>/g' docker-compose.yml

#生成key,记得修改
tr -dc A-Za-z0-9 </dev/urandom | head -c 30 ; echo ''
sed -i 's/REPLACE_MASTER_KEY/<your generated key>/g' docker-compose.yml

wget -O /root/mosquitto.conf https://raw.githubusercontent.com/gravitl/netmaker/master/docker/mosquitto.conf

sudo docker-compose up -d

安装完成后浏览器访问:https://dashboard.<自定义域名> 即可。

创建网络

在 Dashboard 点击 Create Network 即可创建,建议把 UDP Hole Punching 勾选上

创建 Access Key

加入网络需要使用 Access Key,类似于 ZeroTier 中的net-id。

Uses 建议设置大一些,免得后面还的创建。

加入网络

加入网络需要安装Netclient,方法也很简单。

Linux:

  • Debian Distros (debian/ubuntu/mint/pop-os)
1
2
3
4
curl -sL 'https://apt.netmaker.org/gpg.key' | tee /etc/apt/trusted.gpg.d/netclient.asc
curl -sL 'https://apt.netmaker.org/debian.deb.txt' | tee /etc/apt/sources.list.d/netclient.list
apt update -y
apt install netclient wireguard -y
  • Red Hat Distros (fedora/redhat/centos/rocky)
1
2
3
4
5
curl -sL 'https://rpm.netmaker.org/gpg.key' | sudo tee /tmp/gpg.key
curl -sL 'https://rpm.netmaker.org/netclient-repo' | sudo tee /etc/yum.repos.d/netclient.repo
sudo rpm --import /tmp/gpg.key
sudo dnf check-update
sudo dnf install netclient
  • Arch Distros (arch/manjaro/endeavouros)
1
yay -S netclient

Windows:

  • PowerShell script
1
. { iwr -useb  https://raw.githubusercontent.com/gravitl/netmaker/master/scripts/netclient-install.ps1 } | iex; Netclient-Install -version "<your netmaker version>"
  • MSI Installer

Download Link: https://fileserver.netmaker.org/latest/windows/netclient_x86.msi

安装netclient需要提前安装wireguard:Installation - WireGuard

常用命令:

1
2
3
4
#加入网络:
netclient join -t <token>
#离开网络:
netclient leave -n <net-name>

配置 Relay 规则

我们可以在Netmaker仪表盘直观地看到目前的组网情况

默认为下图这种 full mesh(全互联)的状态。

由于节点D0-SFO03至我的PC(surfacebook2)的直连网络状况不是很良好,我选择通过jp-bbtec节点来中转流量。

配置的方式也很简单,来到node页面,添加 Relay 条目即可:

  • 选择 被中转的节点 ,即surfacebook2。

我们可以对比下中转前后的差异:

中转前

中转后


使用 Netmaker 异地组网
http://example.com/2022/07/19/使用Netmaker异地组网/
作者
Rae
发布于
2022年7月19日
许可协议