Friday 27 March 2015

How to Run IPerf Traffic on same Computer with two Interfaces


           Linux PC/Device -----------Eth1--------|
                                  |                            | Loopback cable
                                   |-------------Eth2------- |


  The Iperf traffic should pass externally from the Ethernet interfaces which are connected using Ethernet cable..


We have one interface which is called as loopback interface (lo). When we ping or send traffic to test local interface it is the loopback interface which replies.

Lets say we have three interfaces on Linux PC eth1, eth2 and lo (loopback interface). 


Ifconfig eth1 netmask up
ifconfig eth2 netmask up

ifconfig -> Verify loopback interface is up

ping -> Reply will come

ping -> Reply will come

Now disable loopback interface

ifconfig lo down

ping -> Reply will not come

ping -> Reply will not come

So the problem is if the loopback interface is present this interface will reply and the packets will not go from out side the cable or in other words the kernel detects that the destination is a local one, so the traffic is looped back to the machine itself without going through eth1 or eth2.


Got solution using NAT iptables rules as described in below reference link.

ifconfig eth0 netmask
ifconfig eth1 netmask
iptables -t nat -L
iptables -t nat -A POSTROUTING -s -d -j SNAT --to-source
iptables -t nat -A PREROUTING -d -j DNAT --to-destination
iptables -t nat -A POSTROUTING -s -d -j SNAT --to-source
iptables -t nat -A PREROUTING -d -j DNAT --to-destination
ip route add dev eth0
arp -i eth0 -s 00:22:45:f1:18:53 # eth1's mac address
ip route add dev eth1
arp -i eth1 -s 02:22:23:f1:18:52 # eth0's mac address

Using above commands it was possible to force the traffic outside the cable.

Once setup is ready, run the Iperf server and client on the PC.

# server
iperf -B -s -u -w 256k -l 1KB &
# client
iperf -B -c -u -b 600M -w 256k -l 1KB -P 10 -t 60