simulate incoming packets on a network interface in linux simulate incoming packets on a network interface in linux linux linux

simulate incoming packets on a network interface in linux


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


There are several possible solutions:

  • The quick and dirty solution: Since you have two physical connections, have you considered using a patch cable to connect the two Ethernet ports on your machine? You would then be able to use libpcap to send packets out through eth1 and receive them through eth0. Of course, this solution requires physical access to the machine and you would also lose the ability to use those connections normally.

  • The Right solution: It seems to me that what you are looking for is a way to emulate traffic through a physical network interface. The typical way to do that on Linux (and possibly some other Unix-like systems) is to create a TAP virtual interface. Have a look here for a simple tutorial on TUN/TAP interfaces.

    Unfortunately, tpcreplay does not appear to support TUN/TAP interfaces yet. You might be able to somehow make it work, but I suspect it will be quite awkward.

  • The middle ground: Use a Linux virtual machine on e.g. VirtualBox. I am not sure on the exact network configuration that is needed, but as far as I can tell this should work.


Do you want to send AND receive the packets on the same computer but via particular network card/interface?
The only way that I know of how you can do it is to set up a bounce/echo server.