2

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.

migrated from serverfault.com Jul 16 '13 at 16:15

This question came from our site for system and network administrators.

6

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.
  • 1
    And it goes nowhere. The default gateway is still the gw of the other ISP so traceroute to nexthop shows OK, to anything else - nothing. Besides, how would traceroute know that the default gateway on eth1 is 10.1.0.254 if it is not written anywhere? Routing table only shows default gw 10.0.0.254 link eth0. – Pentium100 Jul 15 '13 at 8:00
  • How do you know that he has 2 interfaces? He wants to use a different router, not a different interface. – Navin Jun 14 '16 at 6:11
  • @Navin I know because it was explicitly stated in the original question! – Michael Hampton Jun 14 '16 at 9:48
2

I had the same problem, but luckily I was able to fix it.

In a multihomed computer, only one default gateway can be defined, regardless of the number of interfaces present. If you try to traceroute to a host that is not in the same subnet as the interface that you are specifying with the -i flag, the traceroute will fail because of the absence of gateway (assuming you are not lucky enough to use the single interface that has a default gateway defined).

The solution to this is to define additional routing tables for every "extra" interface in your machine

A detailed guide can be found in this link.

In Summary if you have 2 interfaces with characteristics:

Interface A: IP: 10.0.0.10    subnet: 255.255.255.0 Gateway 10.0.0.1
Interface B: IP: 192.168.0.10 subnet: 255.255.255.0 Gateway 192.168.0.1

and only the default gateway of A appears in the routing table you would do the following steps to include the gateway of B:

  1. Go to /etc/iproute2/rt_tables and at the end the following line

    1 routingTableB
    
  2. Run as root the following commands:

    ip route add 192.168.0.0/24 dev <Interface B> src 192.168.0.10 table routingTableB
    ip route add default via 192.168.0.1 dev <Interface B> table routingTableB
    ip rule add from 192.168.0.10/32 table routingTableB
    ip rule add to 192.168.0.10/32 table routingTableB
    

After this you will be able to use the -i flag with Interface B without any issue.

Please note that this configuration will be lost after a reboot. Check the link above on how to make it permanent.

As a side note, the flag -g, does not dictate to which IP the interface will send the packets. It is a parameter included in the probes meant to dictate to the intermediate nodes how to route the packets.

1

Posting this in case someone runs into the same problem I did:

On ubuntu, the inetutils-traceroute package does not allow you to set the source interface, whereas the traceroute package does. You almost certainly want the latter.

0

Hmm... Just a concept here but I would say - policy routing:

  1. Add new RT table to your linux

    echo 200 test >> /etc/iproute2/rt_tables

  2. Add policy rule matching it

    ip rule add oif <iface_to_second_ISP> table test

  3. Add default route in your newly crated table

    ip route add 0.0.0.0/0 via <second_ISP_next_hop> dev <iface_to_second_ISP> table test

  4. Flush the caches and test

    ip route flush cache

    ping -I <IP_on_second_ISP_iface> google.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.