我有一个双端口以太网NIC,可以说我已将两个端口循环连接,并将以下IP分配给了两个以太网接口(interface):
我想通过物理网络将流量从1个端口发送到另一个端口,例如从
192.168.3.1
ping 192.168.2.1
。但是,Linux内核中的TCP/IP堆栈识别出这两个地址是本地地址,而是将流量发送到回送适配器,因此流量永远不会到达物理网络。我最接近解决方案的是Anastasov的send-to-self patch,不幸的是,自内核3.6起已停产,因此对我而言它不适用于Ubuntu 13.10(内核3.11)。我试图找到重写3.11的补丁,但似乎无法在Ubuntu发行版中找到它们:
有什么方法可以使自发修补程序正常工作吗?
最佳答案
您可以为此目的使用网络 namespace 。
正如ip-netns
的联机帮助页所述:
A network namespace is logically another copy of the network stack,
with its own routes, firewall rules, and network devices.
以下只是this answer的副本:
创建一个网络 namespace 并将其中一个接口(interface)移入其中:
ip netns add test
ip link set eth1 netns test
在新的命名空间中启动 shell 程序:
ip netns exec test bash
然后,就好像您拥有两台计算机一样。完成后,退出 shell 程序并删除 namespace :
ip netns del test
关于linux - 通过Ubuntu上的物理网络向自己发送流量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22725112/