igoryonya has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to ping, using different gateways, not by binding to different interfaces, but as if you would change the default route, but without changing it?

For example, I have 2 different gateway servers, that can see the other side of the network. Now, I have to do something like this:

route del default
route add default gw gateway1
ping -c 4 address_from_the_net_behind_the_router
route del default
route add default gw gateway2
ping -c 4 address_from_the_net_behind_the_router

This way I determine, if one of the routers has a broken link to the other network, but it disrupts the network flow, which can brake brake a connection, if some file is being copied from the network, behind the gateway, so, I was looking for a non-disruptive way to check it.

I know, that the latest Net::Ping module has a gateway option in the initialization method (new), but I've read it's documentation. It says, that this option is only supported by an IPv6, but I need it for IPv4.

Is there some other module, that allows me to perform such action?

  • Comment on ping an IPv4 address, using different gateways

Replies are listed 'Best First'.
Re: ping an IPv4 address, using different gateways
by Anonymous Monk on Sep 07, 2017 at 10:53 UTC

    I'm assuming you're on linux. One way is to use raw sockets. Another is to go with policy routing.

    The (iputils) ping utility has -m option to mark the packets. So it's just a matter of setting up multiple routing tables with ip rule ... and ip route ....

    Google for "policy routing fwmark", "multiple default route", etc.