如何通过不同的接口路由TCP/IP响应? [英] How to route TCP/IP responses through a different interface?

查看:53
本文介绍了如何通过不同的接口路由TCP/IP响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两台机器,每台机器都有两个有效的网络接口,一个以太网接口eth0和一个tun/tap接口gr0.目标是使用接口gr0在计算机A上启动TCP连接,但随后使计算机B的响应(ACK等)通过以太网接口eth0返回.因此,机器A在gr0上发出SYN,而机器B在自己的gr0上接收SYN,然后通过eth0发回SYN/ACK. tun/tap设备是GNU Radio无线链接,我们只希望响应通过以太网来传递.

I have two machines each with two valid network interfaces, an Ethernet interface eth0 and a tun/tap interface gr0. The goal is to start a TCP connection on machine A using interface gr0 but then have the responses (ACKs, etc) from machine B come back over the Ethernet interface, eth0. So, machine A sends out a SYN on gr0 and machine B receives the SYN on its own gr0 but then sends its SYN/ACK back through eth0. The tun/tap device is a GNU Radio wireless link and we just want the responses to come through the Ethernet.

最简单的方法是什么?我需要对TCP/IP进行更多研究,但是最初我想到的是源欺骗出局数据包将告诉接收方对欺骗后的地址做出响应(应该将其路由到eth0).这将涉及通过gr0从tun/tap接口路由IP,并将其他流量留给eth0.

What's the easiest way to accomplish this? I need to research more on TCP/IP, but I was initially thinking that source-spoofing outgoing packets would tell the receiver to respond to the spoofed address (which should get routed to eth0). This would involve routing the IPs from the tun/tap interfaces through gr0 and leave the other traffic to eth0.

我们正在使用Linux,最好使用Python解决方案.

We are using Linux and a Python solution would be preferable.

感谢您的光临!

推荐答案

您可以在每个系统上的lo接口中添加其他地址,并将这些新地址用作TCP连接端点.然后,您可以使用静态路由来指示每台计算机到达另一台计算机的lo地址所采用的路径.

You could add an additional address to the lo interface on each system and use these new addresses as the TCP connection endpoints. You can then use static routes to direct which path each machine takes to get to the other machine's lo address.

例如:

Machine A:
  ip addr add 1.1.1.1/32 dev lo
  ip route add 2.2.2.2/32 dev eth0 via <eth0 default gateway>

Machine B:
  ip addr add 2.2.2.2/32 dev lo
  ip route add 1.1.1.1/32 dev gr0

然后在计算机A上绑定到1.1.1.1并连接到2.2.2.2.

Then bind to 1.1.1.1 on machine A and connect to 2.2.2.2.

这篇关于如何通过不同的接口路由TCP/IP响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆