ValentinBELYN / icmplib

Easily forge ICMP packets and make your own ping and traceroute.
GNU Lesser General Public License v3.0
267 stars 45 forks source link

Ping requests with source address - problem #32

Closed JohnCCobb closed 3 years ago

JohnCCobb commented 3 years ago

I was using the source parameter on icmplib.ping with the intention of sending a ping request via different interfaces to the same destination. With Linux command line ping you can specify the -I parameter to be either a interface name or an IP address and the first option can be used to get the desired effect, but one can't do this with icmplib.ping. If one merely specifies the desired source address then the ping goes out whatever interface is the default route for the target address which wont be appropriate. It is of course possible to circumvent the problem by matching the source address with an ip rule and directing it to the appropriate interface but this does start to build in dependencies on whatever ip address the interface happens to have and leads to unnecessary complication. Any chance of an option to specify the interface required?

ValentinBELYN commented 3 years ago

Hi @JohnCCobb,

There is the SO_BINDTODEVICE option to select a specific interface for a socket. However, it does not allow you to do what you want. It only defines the source address of the packet, as does the source parameter of the ping function. This option does not modify your routing table and does not force the interface to use.

I don't know how the -I option was implemented on Linux, but it doesn't seem to change the way packets are routed: https://unix.stackexchange.com/a/528478

To do what you want, I recommend you to configure PBR (Policy Based Routing) on your system. Sorry I couldn't help you further. Unfortunately, the solutions are very limited.