基于 zerotier 打洞成功, 但是无法访问到另外一端内网资源

2023-06-23 06:21:35 +08:00
 Eaglemask

各位,自建了 zerotier 并且打洞成功, 且可以访问到另外一端跑了 zerotier 的机器上资源,只是另外一端内网其它资源无法访问到, 具体网络结构如下:

1 台公网 IP 机器(在 vultr 开启了转发并关闭了防火墙)跑了自建 planet 并正常运行, 设置 ip 10.199.188.0/24(内网段 1)自动分发. 网络名称:ABC.

1 台安装在内网的 PVE 机器(192.168.2.99-内网段 2,) 通过 zerotier 加入到上述网络 ABC, 且在 planet 上状态看到在线并拿到了 10.199.188.23.

手机安装了 zerotier(设置激活了 active bridge)加入到上述网络 ABC, 且在 planet 上状态看到在线并拿到了 10.199.188.153.

目前手机可以通过 10.199.188.23 成功访问 PVE 机器本身, 但是 PVE 下一些虚拟机网段在 192.168.2.0/24 机器无法访问到.

请问如何才能访问到 PVE 上几台虚拟机上资源如 gitea/nextcloud 等(此几台虚拟机 Ip 都是固定内网段 2,如 192.168.2.100, 192.168.2.111, 网关为联通路由器 192.168.2.1)

目前尝试了很多教程, 比如 https://www.mrdoc.fun/doc/138/, 同时设置 router 为 target 10.199.188.0/24, 以及网关为 10.199.188.23. 以及另外条路由记录 target 192.168.2.0/24, gateway:192.168.2.99.

但是都失败了, 请问有哪些可以指点下大概问题会出现在哪里? 感谢.

4009 次点击
所在节点    程序员
34 条回复
jllove
2023-06-23 09:15:44 +08:00
看下一个是防火墙两台机器本身的防火墙,另外一个是有些端口可能被墙了,你可以测试一下,Windows 用 telnet 或者 test- connection ,mac 用 nc -vnzu
Evovil
2023-06-23 09:17:22 +08:00
azure2023us928
2023-06-23 09:21:04 +08:00
Pve 上能访问.2 段?

如果能,加上

iptables -I INPUT -s 10.199.188.0/24 -j ACCEPT
azure2023us928
2023-06-23 09:22:09 +08:00
如果不能,贴出

route -na

表信息
Eaglemask
2023-06-23 09:30:54 +08:00
@jllove 两边机器防火墙都关闭了

@azure2023us928
x25 (CCITT X.25)
root@datacenter:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 vmbr0
10.199.188.0 0.0.0.0 255.255.255.0 U 0 0 0 ztqrocq6fm
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 vmbr0
root@datacenter:~#
Eaglemask
2023-06-23 09:34:33 +08:00
@azure2023us928 PVE 机器可以访问.2 段的, 因为它本身就是 192.168.2.99

root@datacenter:~# ping 10.199.188.153
PING 10.199.188.153 (10.199.188.153) 56(84) bytes of data.
64 bytes from 10.199.188.153: icmp_seq=1 ttl=128 time=2.32 ms
64 bytes from 10.199.188.153: icmp_seq=2 ttl=128 time=18.4 ms
64 bytes from 10.199.188.153: icmp_seq=3 ttl=128 time=3.05 ms
64 bytes from 10.199.188.153: icmp_seq=4 ttl=128 time=2.68 ms
^C
--- 10.199.188.153 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 2.318/6.601/18.367/6.797 ms
root@datacenter:~# ping 192.168.2.118
PING 192.168.2.118 (192.168.2.118) 56(84) bytes of data.
64 bytes from 192.168.2.118: icmp_seq=1 ttl=64 time=0.042 ms
64 bytes from 192.168.2.118: icmp_seq=2 ttl=64 time=0.048 ms
64 bytes from 192.168.2.118: icmp_seq=3 ttl=64 time=0.034 ms
^C
--- 192.168.2.118 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2048ms
rtt min/avg/max/mdev = 0.034/0.041/0.048/0.005 ms
Eaglemask
2023-06-23 09:35:05 +08:00
@Evovil 感谢, 我慢慢参考下文档.
azure2023us928
2023-06-23 09:53:17 +08:00
添加 iptables input 没效果?

检查:
1. pve 是否开启 内核转发。
net.ipv4.ip_forward = 1

2. 添加 forward 策略

iptables -I FORWARD -i ztqrocq6fm -j ACCEPT
iptables -I FORWARD -o ztqrocq6fm -j ACCEPT
azure2023us928
2023-06-23 09:55:00 +08:00
建议用 wireguard ,文档比较成熟。

家庭宽带没有公网 ip ?

如果有,直接部署 wireguard server ,手机端装 client ,就可以通过家里的宽带出墙。
Eaglemask
2023-06-23 10:03:50 +08:00
@azure2023us928 #8

都试过啦, 都已经加上了.

9# 我不是要出墙, 宽带没有公网 ip 了, 不过可以打 10010 改为桥接.

至于 wireguard 的话懒得折腾了. zerotier 折腾了一周终于搞定.
Eaglemask
2023-06-23 10:07:13 +08:00
@azure2023us928 8#

root@datacenter:~# iptable -list
-bash: iptable: command not found
root@datacenter:~# iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 10.199.188.0/24 anywhere

Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
DOCKER-USER all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-1 all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain DOCKER (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.17.0.3 tcp dpt:9000

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
RETURN all -- anywhere anywhere

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target prot opt source destination
DROP all -- anywhere anywhere
RETURN all -- anywhere anywhere

Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
root@datacenter:~#
azure2023us928
2023-06-23 10:14:05 +08:00
问题出现在 server 端。

参照 wiregurad

让 2 个 client 之间相互通信。

(建议先说下你想做什么,然后遇到什么问题。而不是直接抛问题,以免别人还要反推你要做什么)

你的架构是 一个 server ( vultr ),2 个 client ( pve+手机),目的是想让两个 client 之间无缝隙通信。



www.v2ex.com/t/910055

看实现部分,iptables -I FORWARD -i wg0 -o wg0 -j ACCEPT ( server 端)
azure2023us928
2023-06-23 10:17:19 +08:00
server 端试试加一条 route

让 192.168.2.0/24 的流量走 wg0

ip route add 192.168.2.0/24 dev wg0
Eaglemask
2023-06-23 10:20:54 +08:00
@azure2023us928 我倒是打算测试下自建 tailscale, 不知道这个是否有 ios 端?
azure2023us928
2023-06-23 10:23:05 +08:00
@Eaglemas 没用过,我只用最简单,最原始的 wireguard 。它们大概都是参照 wireguard ,加了一些特性,这些特性是非必须的。
oneisall8955
2023-06-23 10:37:37 +08:00
1. 在 ztncui 后台的网络 ABC 添加路由
192.168.2.0/24 via 10.199.188.23 ,这时候每个 zt client 都会得到一条路由表,Linux 通过 route -n 查看,window 通过 route print 查看

2. 在 pve ( 192.168.2.99 即 10.199.188.23 )开启转发及 iptables 包转换

2.1 `cat /proc/sys/net/ipv4/ip_forward`看下是否转发,0 的时候,直接 `echo 1 > /proc/sys/net/ipv4/ip_forward`

2.2 ifconfig 查看 zt 的网卡名称,也就是 zt 开头,IP 为 10.199.188.23 的网卡,如:ztxxxxxxxx

2.3 iptables 添加允许及包转换,需要将 ztxxxxxxx 替换成你实际的 ifconfig 的网卡名称

iptables -I FORWARD -i ztxxxxxxxx -j ACCEPT

iptables -| FORWARD -o ztxxxxxxxx -j ACCEPT

iptables -t nat -I POSTROUTING -o ztxxxxxxxx -j MASQUERADE


网上很多教程类似的,例如
https://www.key-iot.com/news/77793.html ,上面总结希望对你有帮助
Eaglemask
2023-06-23 10:54:57 +08:00
@oneisall8955

1. 在 ztncui 后台的网络 ABC 添加路由
192.168.2.0/24 via 10.199.188.23 ,这时候每个 zt client 都会得到一条路由表,Linux 通过 route -n 查看,window 通过 route print 查看
已增加并可以看到

2. 在 pve ( 192.168.2.99 即 10.199.188.23 )开启转发及 iptables 包转换
已经启用

2.1 `cat /proc/sys/net/ipv4/ip_forward`看下是否转发,0 的时候,直接 `echo 1 > /proc/sys/net/ipv4/ip_forward`
已启用

2.2 ifconfig 查看 zt 的网卡名称,也就是 zt 开头,IP 为 10.199.188.23 的网卡,如:ztxxxxxxxx
没问题.

2.3 iptables 添加允许及包转换,需要将 ztxxxxxxx 替换成你实际的 ifconfig 的网卡名称

iptables -I FORWARD -i ztxxxxxxxx -j ACCEPT

iptables -| FORWARD -o ztxxxxxxxx -j ACCEPT

iptables -t nat -I POSTROUTING -o ztxxxxxxxx -j MASQUERADE

都已经按照教程增加.
wtsamuel
2023-06-23 11:27:04 +08:00
我遇到的问题和你的差不多,安装 zerotier 的机器可以访问,同一局域网下机器不能访问
我这个好像是主路由防火墙的问题,必须 ip 伪装。我提供 dhcp 的主路由是 openwrt ,在防火墙下有个 zone 的地方,lan -> wan 的 Masquerading 不开启,wan -> accept 的 Masquerading 开启
Eaglemask
2023-06-23 11:31:17 +08:00
@wtsamuel 我的路由器是运营商的, 防火墙改为最低了, 进不去 ssh, 否则可以进去关闭防火墙或者安装那个 fake ip.

实在不行, 我打算在 PVE 中装一个 istoreos/openwrt 之类的来进行拨号并启用 dhcp, 这样也可以启用 fake ip
mikaelson
2023-06-23 11:34:34 +08:00
我用 tinc ,最近组网成功后,连接也一直丢包,好奇怪。。。从没碰到过。。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/950964

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX