V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  lilogo  ›  全部回复第 6 页 / 共 9 页
回复总数  163
1  2  3  4  5  6  7  8  9  
2020-02-11 22:56:47 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@izoabr
@weyou 根据 #31 的方法 A、B 两个节点已经通了,感谢!
但是这只解决了一半的问题,因为 A、B 两个是路由器,A、B 虽然可以互通,但是 A、B 两个路由后端的机器还是没有通。我是想在 A、B 两个节点增加一下 iptables MASQUERADE:
```
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
```
不过还是 ping 不通 A、B 后面的其他主机,如下,
在 A 节点 ping B 路由器后面的主机( IP 为 10.200.30.67 ):
```
root@OpenWrt:~# ping 10.200.30.67
PING 10.200.30.67 (10.200.30.67): 56 data bytes
^C
--- 10.200.30.67 ping statistics ---
9 packets transmitted, 0 packets received, 100% packet loss
root@OpenWrt:~#
```
此时在 B 路由器上 tcpdump -i tun0 已经收到包了,但是还是不通:
```
root@OpenWrt:~# tcpdump -i tun0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on tun0, link-type RAW (Raw IP), capture size 262144 bytes
14:53:53.548755 IP6 fe80::31ad:504:165b:1666.546 > ff02::1:2.547: dhcp6 solicit
14:53:53.648347 IP 172.16.14.1 > 10.200.30.67: ICMP echo request, id 53116, seq 5, length 64
14:53:53.648366 IP 172.16.14.2 > 172.16.14.1: ICMP 10.200.30.67 protocol 1 port 11387 unreachable, length 92
14:53:54.648702 IP 172.16.14.1 > 10.200.30.67: ICMP echo request, id 53116, seq 6, length 64
14:53:54.648722 IP 172.16.14.2 > 172.16.14.1: ICMP 10.200.30.67 protocol 1 port 57910 unreachable, length 92
14:53:55.648533 IP 172.16.14.1 > 10.200.30.67: ICMP echo request, id 53116, seq 7, length 64
14:53:55.648553 IP 172.16.14.2 > 172.16.14.1: ICMP 10.200.30.67 protocol 1 port 46322 unreachable, length 92
^C
7 packets captured
7 packets received by filter
0 packets dropped by kernel
root@OpenWrt:~#
```
2020-02-11 22:44:31 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@sujin190 #11 并没有通啊
2020-02-11 22:19:52 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@izoabr
@weyou 问下经过 tun0 设备到对端局域网的路由应该是指定对端的 vpn ip 还是本节点的 vpn ip ?
如下是 A 节点,VPN 分配的 IP 地址是 172.16.14.1:
```
root@OpenWrt:~# ip addr show | grep '172.16.14.'
inet 172.16.14.1/24 scope global tun0
root@OpenWrt:~#
```

那么配置的路由应该是下面的哪一个呢?(我都试过了两个都不行。。)
```
root@OpenWrt:~# # via 本节点 IP
root@OpenWrt:~# ip route add 192.168.1.0/24 via 172.16.14.1
root@OpenWrt:~# # via 对方 IP
root@OpenWrt:~# ip route add 192.168.1.0/24 via 172.16.14.2
root@OpenWrt:~#
```
2020-02-11 22:08:42 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@izoabr 应该不会过滤 icmp 吧,我单纯的 ping vpn 网段和内网的网段的话都是可以响应的
2020-02-11 22:03:53 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@weyou tinc 网络都已经好了。hosts 文件里路由?是指 tinc 的路由吗?我没有在 hosts 文件里面设置路由,就是 tinc-up 后台 tinc-down 文件里面设置了 ip,路由的话是我命令行手工添加的。
2020-02-11 22:00:35 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@pubby 是的,两台都是 openwrt。既然 vpn 接口不需要加 nat 的话,那么理论上来说 #13 楼的应该有效了,但似乎不行。而且不需要 nat 的话,那么最简单的方案就是:关闭 iptables、指定经过 tun0 设备的到对方网段的 route、开启 ip forward。

这三步就应该 OK 了啊。。。
2020-02-11 21:42:30 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@weyou 两个网络是在不同的局域网的,分属不同的公网也不需要 nat 吗?
2020-02-11 20:49:33 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@weyou 我加的是这个,出口设备 tun0:
```
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
```
即使换成 br-lan 也不行
2020-02-11 19:58:53 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@hawhaw @izoabr 是不是除了路由的部分还需要配置 iptables 的 MASQUERADE ?
2020-02-11 19:51:53 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@izoabr 从 10.200.30.55 上面 ping 和 traceroute 如下:
```
root@OpenWrt:~# traceroute 172.16.14.1
traceroute to 172.16.14.1 (172.16.14.1), 30 hops max, 46 byte packets
1 172.16.14.1 (172.16.14.1) 5.377 ms 5.160 ms 4.769 ms
root@OpenWrt:~#
root@OpenWrt:~# ping 172.16.14.1
PING 172.16.14.1 (172.16.14.1): 56 data bytes
64 bytes from 172.16.14.1: seq=0 ttl=64 time=5.329 ms
64 bytes from 172.16.14.1: seq=1 ttl=64 time=5.603 ms
^C
--- 172.16.14.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 5.329/5.466/5.603 ms
root@OpenWrt:~#
```
另外,是否和 17216.14.0/24 这个是 VPN 网段即 tun 设备有关系?
2020-02-11 19:48:34 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@hawhaw 按照你的步骤 1-4,在执行完第 4 步时依然 ping 不通,步骤如下:

A 节点:
```
root@OpenWrt:~# ip route show
default via 53.3.94.1 dev pppoe-wan proto static
53.3.94.1 dev pppoe-wan proto kernel scope link src 53.3.94.180
192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.1
172.16.14.0/24 dev tun0 proto kernel scope link src 172.16.14.1
root@OpenWrt:~# ip route add 10.200.30.0/24 via 172.16.14.1
root@OpenWrt:~# cat /proc/sys/net/ipv4/ip_forward
1
root@OpenWrt:~# /etc/init.d/firewall stop
Warning: Section @zone[1] (wan) cannot resolve device of network 'wan6'
* Flushing IPv4 filter table
* Flushing IPv4 nat table
* Flushing IPv4 mangle table
* Flushing IPv4 raw table
* Flushing IPv6 filter table
* Flushing IPv6 nat table
* Flushing IPv6 mangle table
* Flushing conntrack table ...
root@OpenWrt:~#
```




B 节点:
```
root@OpenWrt:~# ip route add 192.168.1.0/24 via 172.16.14.2
root@OpenWrt:~# /etc/init.d/firewall stop
Warning: Unable to locate ipset utility, disabling ipset support
Warning: Section @zone[1] (wan) cannot resolve device of network 'wan'
Warning: Section @zone[1] (wan) cannot resolve device of network 'wan6'
Warning: Section @zone[1] (wan) has no device, network, subnet or extra options
* Flushing IPv4 filter table
* Flushing IPv4 nat table
* Flushing IPv4 mangle table
* Flushing IPv6 filter table
* Flushing IPv6 mangle table
* Flushing conntrack table ...
root@OpenWrt:~# cat /proc/sys/net/ipv4/ip_forward
1
root@OpenWrt:~#
root@OpenWrt:~# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1): 56 data bytes
^C
--- 192.168.1.1 ping statistics ---
15 packets transmitted, 0 packets received, 100% packet loss
root@OpenWrt:~#
```

B 节点 ping A 节点抓包:
```
root@OpenWrt:~# tcpdump -i tun0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on tun0, link-type RAW (Raw IP), capture size 262144 bytes
11:35:14.283993 IP6 fe80::31ad:504:165b:1666.63363 > ff02::c.1900: UDP, length 146
11:35:16.238521 IP 172.16.14.2 > 192.168.1.1: ICMP echo request, id 26670, seq 0, length 64
11:35:16.238591 IP 192.168.1.1 > 172.16.14.2: ICMP net 192.168.1.1 unreachable - unknown, length 92
11:35:17.238794 IP 172.16.14.2 > 192.168.1.1: ICMP echo request, id 26670, seq 1, length 64
11:35:17.238847 IP 192.168.1.1 > 172.16.14.2: ICMP net 192.168.1.1 unreachable - unknown, length 92
11:35:17.285547 IP6 fe80::31ad:504:165b:1666.63363 > ff02::c.1900: UDP, length 146
11:35:18.238836 IP 172.16.14.2 > 192.168.1.1: ICMP echo request, id 26670, seq 2, length 64
11:35:18.238885 IP 192.168.1.1 > 172.16.14.2: ICMP net 192.168.1.1 unreachable - unknown, length 92
11:35:19.238940 IP 172.16.14.2 > 192.168.1.1: ICMP echo request, id 26670, seq 3, length 64
11:35:19.238995 IP 192.168.1.1 > 172.16.14.2: ICMP net 192.168.1.1 unreachable - unknown, length 92
11:35:20.238975 IP 172.16.14.2 > 192.168.1.1: ICMP echo request, id 26670, seq 4, length 64
```
2020-02-11 19:07:23 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@sujin190 打开转发是第一步,肯定开了
2020-02-11 17:30:12 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@izoabr
从 B 上 traceroute A 的情况:
```
root@OpenWrt:~# traceroute 172.16.14.1
traceroute to 172.16.14.1 (172.16.14.1), 30 hops max, 46 byte packets
1 172.16.14.1 (172.16.14.1) 5.077 ms 5.189 ms 4.681 ms
root@OpenWrt:~# traceroute 192.168.1.1
traceroute to 192.168.1.1 (192.168.1.1), 30 hops max, 46 byte packets
1 192.168.1.1 (192.168.1.1) 0.003 ms !U 0.002 ms !U 0.002 ms !U
root@OpenWrt:~#
```

从 A 上 traceroute B 的情况:
```
root@OpenWrt:~# traceroute 172.16.14.2
traceroute to 172.16.14.2 (172.16.14.2), 30 hops max, 38 byte packets
1 172.16.14.2 (172.16.14.2) 6.088 ms 4.304 ms 4.858 ms
root@OpenWrt:~# traceroute 10.200.30.55
traceroute to 10.200.30.55 (10.200.30.55), 30 hops max, 38 byte packets
1 10.200.30.55 (10.200.30.55) 1.315 ms !U 0.031 ms !U 0.030 ms !U
root@OpenWrt:~#
```
2020-02-11 16:10:17 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
抱歉上一条有一行错了,参考这个:
A 节点的:
```
root@OpenWrt:~# ip route show
default via 53.3.94.1 dev pppoe-wan proto static
10.200.30.0/24 via 172.16.14.2 dev tun0
53.3.94.1 dev pppoe-wan proto kernel scope link src 53.3.94.180
192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.1
172.16.14.0/24 dev ztmjffzrix proto kernel scope link src 172.16.14.1
172.16.14.0/24 dev tun0 proto kernel scope link src 172.16.14.1
192.168.133.0/24 dev tun1 proto kernel scope link src 192.168.133.1
root@OpenWrt:~# ip ru sh
0: from all lookup local
1001: from all iif pppoe-wan lookup main
2001: from all fwmark 0x100/0x3f00 lookup 1
2061: from all fwmark 0x3d00/0x3f00 blackhole
2062: from all fwmark 0x3e00/0x3f00 unreachable
32766: from all lookup main
32767: from all lookup default
root@OpenWrt:~#
```

B 节点的:
```
root@OpenWrt:~# ip route show
default via 10.200.30.250 dev br-lan src 10.200.30.1
10.200.30.0/24 dev br-lan scope link src 10.200.30.1
192.168.1.0/24 via 172.16.14.1 dev tun0
172.16.14.0/24 dev tun0 scope link src 172.16.14.2
root@OpenWrt:~# ip ru sh
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
root@OpenWrt:~#
```

@izoabr
2020-02-11 16:05:05 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
A 节点的:
```
root@OpenWrt:~# ip route show
default via 53.3.94.1 dev pppoe-wan proto static
10.200.30.0/24 via 172.16.14.122 dev tun0
53.3.94.1 dev pppoe-wan proto kernel scope link src 53.3.94.180
192.168.1.0/24 dev br-lan proto kernel scope link src 192.168.1.1
172.16.14.0/24 dev ztmjffzrix proto kernel scope link src 172.16.14.1
172.16.14.0/24 dev tun0 proto kernel scope link src 172.16.14.1
192.168.133.0/24 dev tun1 proto kernel scope link src 192.168.133.1
root@OpenWrt:~# ip ru sh
0: from all lookup local
1001: from all iif pppoe-wan lookup main
2001: from all fwmark 0x100/0x3f00 lookup 1
2061: from all fwmark 0x3d00/0x3f00 blackhole
2062: from all fwmark 0x3e00/0x3f00 unreachable
32766: from all lookup main
32767: from all lookup default
root@OpenWrt:~#
```

B 节点的:
```
root@OpenWrt:~# ip route show
default via 10.200.30.250 dev br-lan src 10.200.30.1
10.200.30.0/24 dev br-lan scope link src 10.200.30.1
192.168.1.0/24 via 172.16.14.1 dev tun0
172.16.14.0/24 dev tun0 scope link src 172.16.14.2
root@OpenWrt:~# ip ru sh
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
root@OpenWrt:~#
```
@izoabr
2020-02-11 15:50:30 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@izoabr
@jasonyang9 在 B 上加上了到 A 的路由依然不行:

```
ip route add 192.168.1.0/24 via 172.16.14.1
```
2020-02-11 15:42:59 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
补充下所有主机都是可 ping 的,而且直接在 A、B 节点上 ping 172.16.14.0/24 网段内机器都是可以 ping 通的。
另外 tcpdump 抓虚拟网卡的命令是 tcpdump -i tun0
2020-02-11 15:34:57 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
在 A 节点机器 ping B 节点时,在 A 节点上使用 `tcpdump tun0` 抓包如下:

```
15:28:25.364435 IP 172.16.14.1 > 10.200.30.55: ICMP echo request, id 63083, seq 19, length 64
15:28:25.364779 IP 10.200.30.55 > 172.16.14.1: ICMP net 10.200.30.55 unreachable - unknown, length 92
15:28:26.364657 IP 172.16.14.1 > 10.200.30.55: ICMP echo request, id 63083, seq 20, length 64
15:28:26.365404 IP 10.200.30.55 > 172.16.14.1: ICMP net 10.200.30.55 unreachable - unknown, length 92
15:28:27.364882 IP 172.16.14.1 > 10.200.30.55: ICMP echo request, id 63083, seq 21, length 64
15:28:27.365638 IP 10.200.30.55 > 172.16.14.1: ICMP net 10.200.30.55 unreachable - unknown, length 92
15:28:28.365165 IP 172.16.14.1 > 10.200.30.55: ICMP echo request, id 63083, seq 22, length 64
15:28:28.365573 IP 10.200.30.55 > 172.16.14.1: ICMP net 10.200.30.55 unreachable - unknown, length 92
```
2020-02-11 15:18:51 +08:00
回复了 lilogo 创建的主题 宽带症候群 请教 iptables 防火墙及路由配置的打通两地局域网的问题
@jasonyang9 应该不是这个原因,理论上 B 收到的包应该是来自 172.16.14.1 的,而不是 192.168.1.1 的,而 172 网段的是 VPN 网段,本身即可正常通信。
1  2  3  4  5  6  7  8  9  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   929 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 16ms · UTC 22:35 · PVG 06:35 · LAX 15:35 · JFK 18:35
Developed with CodeLauncher
♥ Do have faith in what you're doing.