3

ip route get 2607:f8b0:4005:804::200e will show me the best (longest prefix) route to google.com, but it does not show all routes that can take me there.

Right now I am using ip -6 route show | grep 2607:f8b0:. This prints the right routes, but it also prints every other route in that /32.

There has got to be a better way.

  • see traceroute or tracepath – Rui F Ribeiro Jul 18 '16 at 13:27
  • do you mean the route that's taken (which interface) out of the server, or once it's on the capital-I Internet? – Jeff Schaller Jul 18 '16 at 13:27
  • @JeffSchaller Both, I have a linux router connected to multiple upstreams and an IX leading to the Internet. These commands run on that router. – Navin Jul 18 '16 at 23:32
  • @RuiFRibeiro No, traceroute only shows 1 path via the longest prefix route. I'm looking for all possible 1st hops (gateways) in my routing table. – Navin Jul 18 '16 at 23:33
  • What routing program are you running? Usually only the best route gets installed in the kernel and that's what you are seeing. To see all the candidate routes, you would need to ask the routing daemon. Until we know which, we can't say how you do this (other than RTFM). – MAP Jul 19 '16 at 3:45
7

There is an easy way to list all routes matchig prefix on linux :

ip -6 route list match 2607:f8b0:4005:804::200e table all

This will list all possible routes to specified target (including default, if no more specific is found) in all tables. Obviously, this works for IPv4 too.

PS: I know that my answer is a bit too late, and most likely you have figured this on your own already, but nevertheless - whoever hits this question may find it helpful :)

0

If I'm interpreting this right, you want to find out if a particular ipv6 address (google.com's) is contained within a routing table entry (network/netmask), and print the route if it is.

If so, then:

  1. Acquire google.com's ipv6 address, e.g. with host -t aaaa

  2. Get a list of all ipv6 routes. e.g. with ip -6 route show. or query your routing daemon for a list.

  3. For each ipv6 route, check if google.com's ipv6 address is contained within that network and netmask.

The perl Net::CIDR module has a cidrlookup() function for checking if an IP address is in a net block (or array of net blocks) - it works with both ipv4 and ipv6 addresses. perl also has a Net::DNS module for doing DNS lookups, and probably has module(s) for fetching routing tables from various routers/routing-daemons - perl has a module (or two. or a dozen) to do almost anything you can think of. It's easy enough to extract what you need from the output of ip -6 route show anyway.

NOTE: this will only find matches where there is a specific route in your routing table for a network/mask which contains your target IP. The "default" route contains every IP, of course.

If you prefer not to use perl, there's also libcidr. Shouldn't be too hard to write your own (or someone may already have done it).

  • I was hoping I wouldn't have to write it myself, but I'll go ahead and accept this answer since nobody else understood the question. Maybe I'll make a patch for iproute2 which adds an --all flag to ip route get :) – Navin Jul 19 '16 at 10:47
  • The algorithm's pretty simple, translating from my pseudo-code to perl would only take about 10 lines of code. There's probably python libraries to do the same. Patching iproute2 sounds like a good idea. – cas Jul 19 '16 at 11:14

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.