【问题标题】:How do I hide a network interface from a process under Linux?如何在 Linux 下隐藏进程中的网络接口?
【发布时间】:2013-01-17 17:49:13
【问题描述】:

我正在尝试使用具有 2 个端口(eth1、eth2)的 10G 网卡进行一些网络测试。 为了测试,我会使用类似 iperf 的东西来做带宽测试:

我将电缆直接从端口 1(eth1) 连接到端口 2(eth2)。

IP 地址:

eth1: 192.168.20.1/24
eth2: 192.168.20.2/24

1号航站楼:

user@host:~$ iperf -s -B 192.168.20.1

2号航站楼:

user@host:~$ iperf -c 192.168.20.1

结果:

------------------------------------------------------------
Client connecting to 192.168.20.1, TCP port 5001
TCP window size:  169 KByte (default)
------------------------------------------------------------
[  3] local 192.168.20.1 port 53293 connected with 192.168.20.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  41.6 GBytes  35.7 Gbits/sec

如您所见,数据根本不通过电缆,而是通过本地主机或内存,这就是为什么我的速度超过 10G。

是否可以从命令“iperf -c 192.168.20.1”中隐藏eth1,从而强制数据通过电缆?

更新 1:

在@Mardanian 引用之后,我现在尝试了以下方法:

Note: Ports are now eth2/eth3 (not eth1/eth2)
eth2 has mac address 00:40:c7:6c:01:12
eth3 has mac address 00:40:c7:6c:01:13

ifconfig eth2 192.168.20.1/24 up
ifconfig eth3 192.168.20.2/24 up
arp -s 192.168.20.3 00:40:c7:6c:01:12
arp -s 192.168.20.4 00:40:c7:6c:01:13
ip route add 192.168.20.3 dev eth3
ip route add 192.168.20.4 dev eth2
iptables -t nat -A POSTROUTING -d 192.168.20.4 -j SNAT --to-source 192.168.20.3
iptables -t nat -A POSTROUTING -d 192.168.20.3 -j SNAT --to-source 192.168.20.4
iptables -t nat -A PREROUTING -d 192.168.20.3 -j DNAT --to-destination 192.168.20.1
iptables -t nat -A PREROUTING -d 192.168.20.4 -j DNAT --to-destination 192.168.20.2

iperf -s -B 192.168.20.3
bind failed: Cannot assign requested address

这些虚拟地址似乎无法正常工作,我似乎无法绑定甚至 ping 它们。

arp -an
? (192.168.20.3) at 00:40:c7:6c:01:12 [ether] PERM on eth2
? (192.168.20.4) at 00:40:c7:6c:01:13 [ether] PERM on eth3

据我了解,arp 不会将 ip 地址绑定到接口,它只是告诉系统为了找到某个 ip,它让系统知道要通过哪个接口 - 这就是为什么我不能绑定到虚拟 IP 地址。如果我绑定到真实的 IP 地址,那么我仍然会通过本地系统。

【问题讨论】:

    标签: networking bandwidth


    【解决方案1】:

    如果 iperf 检测到目标是本地的,它将始终使用环回。强制内核通过接口路由它。见linux: disable using loopback and send data via wire between 2 eth cards of one comp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多