前言:最近将debian系统替代了openwrt作为家庭网络中枢,实现了openwrt的所有功能。其中内网穿透是个老话题了,之前也用过tailscale之类的内网穿透工具,发现udp打洞成功后,在本地不同运营商之间zerotier的延迟还要更低,tailscale会出现已经连上,但无法ping通的情况,zerotier更稳定,只要通了就稳定了。那现在加个zerotier岂不完美?
- 切换root用户
sudo -i
- debian一键脚本安装zerotier
curl -s https://install.zerotier.com | bash
- 加入zerotier网络
zerotier-cli join <ZeroTier network ID>
- 开启路由转发
输入nano /etc/sysctl.conf
,将net.ipv4.ip_forward=1
前面#
去掉,重启 - 开启zt网络和本地网络之间的nat和转发
其中eth0
为你的本地网卡,zxxxxxx
为你的zt网络设备
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o zxxxxxx -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i zxxxxxx -o eth0 -j ACCEPT
- 开启iptables持久化,重启后自动执行
- 删除默认nftables和依赖
apt-get remove --auto-remove nftables
apt-get purge nftables
- 清空iptables
iptables -P INPUT ACCEPT
iptables -F
iptables -X
- 检查iptables
iptables -L -v
- 安装iptables持久化Iptables Persistent
apt-get install iptables-persistent
- 添加了新的规则,需要持久化,执行
iptables-save > /etc/iptables/rules.v4
- 恢复原持久化备份
iptables-restore < /etc/iptables/rules.v4
- 设置zt管理页面上的路由转发
添加如下,172.29.110.1
为debian设备分配的zt网络ip;192.168.1.0/23
为你希望转发的本地网段,没有设置为/24
是因为这样赋给了ZeroTier路由较低优先级,物理连接到网络的设备将使用他们的物理连接:192.168.1.0/23 via 172.29.110.1
基本上现在你实现了内网的穿透,用手机安装zerotier客户端加入zt网络后会发现能实现所有内网功能。如果ping值不理想,说明udp打洞不顺利,下集会讲讲部署zt moon,实现Relay中继,协助打洞成功。
0 条评论