zerotier转发(iptables配置)
网络三层NAT配置方法(linux主机)
- 假设zerotier虚拟局域网的网段是192.168.192.0 局域网A 192.168.1.0 局域网B 192.168.2.0
- (如果需要互联)在局域网A和B中需要各有一台主机安装zerotier并作为两个内网互联的网关
- 分别是192.168.1.10(192.168.192.10) 192.168.2.10(192.168.192.20)#括号里面为虚拟局域网的IP地址
1. 在zerotier网站的networks里面的Managed Routes下配置路由表,增加如下内容
192.168.1.0/24 via 192.168.192.10
192.168.2.0/24 via 192.168.192.20
2. 开启内核转发
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
#与zt以外网卡互通
zerotier-cli set [zt网络号] allowGlobal=1
zerotier-cli set [zt网络号] allowDefault=1
sysctl -p
3. 防火墙设置
sudo iptables -A FORWARD -i ztly53odaw -o eth0 -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o ztly53odaw -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables-save
参考: Route between ZeroTier and Physical Networks - ZeroTier Knowledge Base - Confluence (atlassian.net)https://zerotier.atlassian.net/wiki/spaces/SD/pages/224395274/Route+between+ZeroTier+and+Physical+Networks
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o ztly53odaw -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i ztly53odaw -o eth0 -j ACCEPT
iptables-save
旧版zerotier “cannot bind local interface port”或无法接入网络处理
killall -9 zerotier-one //杀死zerotier所有进程
netstat -lp | grep zero //查看9993端口是否被占用
zerotier-one -d //启动zerotier客户端
zerotier-cli listnetworks //列出连接的zerotier网络
看到status这一项为ACCESS_DENIED说明端口绑定成功