一个关于 gre 与流量转发的问题,求大神帮忙~

2020-07-08 10:49:38 +08:00
 Raul7

A 机器建立与 B 机器连接的 gre 通道(并把 10000 端口通过 gre 通道转发到 B 机器):

ip link add gre-y type gre local A 机器 ip remote B 机器 ip ttl 64
ip link set gre-y up
ip addr add 10.1.1.2/24 dev gre-y
iptables -t nat -I PREROUTING -p tcp --dport 10000 -j DNAT --to-destination 10.1.1.3:10000

B 机器建立与 A 机器连接的 gre 通道:

ip link add gre-x type gre local B 机器 ip remote A 机器 ip ttl 64
ip link set gre-x up
ip addr add 10.1.1.3/24 dev gre-x

B 机器上的 10000 端口是通过 docker 启的,B 机器ifconfig如下:

[root@localhost ~]# ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:b5ff:fe37:829d  prefixlen 64  scopeid 0x20<link>
        ether 02:42:b5:37:82:9d  txqueuelen 0  (Ethernet)
        RX packets 1748106  bytes 280406387 (267.4 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1747699  bytes 748575892 (713.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

gre-x: flags=209<UP,POINTOPOINT,RUNNING,NOARP>  mtu 1476
        inet 10.1.1.3  netmask 255.255.255.0  destination 10.1.1.3
        inet6 fe80::5efe:c0a8:8eb1  prefixlen 64  scopeid 0x20<link>
        unspec C0-A8-8E-B1-00-00-C0-9B-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 748  bytes 42201 (41.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 800  bytes 62808 (61.3 KiB)
        TX errors 28  dropped 0 overruns 0  carrier 0  collisions 28

我的需求是:B 机器收到 A 机器( 10.1.1.2 )的请求,默认走 B 机器的 gre-x 网卡,随后 B 机器通过 10.1.1.3 返回的流量默认从 gre-x 网卡返回。B 机器上是这么配置的:

ip route add default via 10.1.1.2 dev gre-x table 111
ip rule add pref 1000 from 10.1.1.3 lookup 111

但是流量返回不回去,B 机器上抓包发现问题: A(10.1.1.2) -> B 机器 -> docker 启的 10000 端口( 172.17.0.x )-> 流量从 172.17.0.x 返回。

以至于 A 机器端口转发到 B 机器,无法联通。求助大家该如何解决?

1784 次点击
所在节点    Linux
4 条回复
defunct9
2020-07-08 11:50:20 +08:00
不知道要搞乜,弄得这么复杂干嘛,GRE 一般 BGP 用来 peer,或者隧道两个网段用。
Raul7
2020-07-08 13:43:27 +08:00
@defunct9 为了把 A 的端口转发到 B 端口 然后 B 能拿到原始请求 ip
defunct9
2020-07-08 14:37:33 +08:00
肯定能通,调试一下吧。股市这么好,看股市去了,没时间帮忙了。
julyclyde
2020-07-08 15:50:52 +08:00
rp_filter 关闭就行了

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

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

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

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

© 2021 V2EX