Linux – traceroute with explicit gateway selection

linuxtraceroute

I have a router (running Linux) that is connected to two ISPs, the routes are selected using BGP, however, I would like to ping/trace each connection separately.

The standard traceroute command seems to be able to do it (allow selection of outgoing interface, source IP), but it does not allow selection of the gateway. While there is a command line option (-g), all it does is set the IP routing option instead of just sending the packet there.

Here's what I want:
Let's say My router has two IPs – 10.0.0.1 (given by first ISP), 10.1.0.1 (given by second ISP). The default gateway (next hop) on the first ISP is 10.0.0.254 and on the second is 10.1.0.254. One of them is selected as the current default gateway (by BGP), but I also want to be able to use trace/ping trough the other gateway. I cannot change the routing table (without causing connection interruptions, especially if the other ISP has a problem).

traceroute_oth –nexthop 10.0.0.254 8.8.8.8 should give

1 10.0.0.254
2 some-iother-ip.first-isp.com
...
x 8.8.8.8

traceroute_oth –nexthop 10.1.0.254 8.8.8.8 should give

1 10.1.0.254
2 some-ip.second-isp.com
...
x 8.8.8.8

EDIT: "traceroute -i" does not work because the router does not know the other gateway. Basically, the routing table is this (simplified):

0.0.0.0/0 gw 10.0.0.254 eth0

There is no way for the program to know what the default gateway on eth1 (link to the other ISP) is without me explicitly specifying it.

Best Answer

You did read the man page, right?

   -i interface, --interface=interface
          Specifies  the  interface  through  which traceroute should send
          packets. By default, the interface is selected according to  the
          routing table.
Related Question