Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simulate incoming packets on a network interface in linux

If you normally send tcpreplay of a pcap through an interface say eth0 , the packets are outbound, ie will go out through the network card . Is there any way i can make the pcaps inbound so that my system should process it as an inbound packet?

Possible Scenario

I have an application that receives packet from eth0, extract some details from the packet and sends it through eth1. Now the situation is fine if the network is setup and real packets actually flow in to my system. But for testing purposes , i do not have anything connected to my eth0 or eth1 ports , but i still want to create similar kind of traffic from a pcap(probably through a script ) so that i dont have to depend on an external physical network connection for testing the application.

like image 594
woodstok Avatar asked Aug 10 '12 12:08

woodstok


1 Answers

Replace eth0 with lo

  1. Run your application which receives packets from lo and sends packets to eth1
  2. Run another program (packet generator) which send packets to lo

every packet send to lo will be received by lo again, so your application will receive packets from your packet generator.

if your lo is busy with other packets, you can add more loopback device by kernel argument max_loop=x

like image 68
Zang MingJie Avatar answered Nov 09 '22 03:11

Zang MingJie