【笔记】MacOS部署Zerotier

前言

MacOS部署Zerotier

MacOS加入到Zerotier网络

下载依赖

1
brew install zerotier-one

加入网络

1
zerotier-cli join <network_id>

在Zerotier控制器中授权MacOS

Zerotier网络内的设备访问MacOS的内网设备

Zerotier控制器的配置

  • 访问Zerotier控制器https://my.zerotier.com/

  • Advanced配置中Destination配置为MacOS的内网网段(192.168.0.0/24)、Via配置为OpenWRT在Zerotier网络域中被分配的IP地址(192.168.1.2)->Submit

开启IP转发

1
sudo sysctl -w net.inet.ip.forwarding=1

开机自启

1
echo "net.inet.ip.forwarding=1" >> /etc/sysctl.conf

配置防火墙

修改配置文件

  • anchor规则前添加一条nat规则,将来自Zerotier的流量转发给MacOS所在的内网网关

en0:指定能够访问内网网关的网卡
192.168.0.1:指定内网网关
192.168.1.0/24:指定Zerotier网段

/etc/pf.conf
1
2
3
4
5
6
7
8
9
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
dummynet-anchor "com.apple/*"

nat on en0 from 192.168.1.0/24 to any -> 192.168.0.1

anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"

应用配置文件

1
sudo pfctl -e -f /etc/pf.conf

完成