API to query the routing table entry to reach the specified destination

Is there an API to find out which routing table entry the OS will use to send a packet to the specified destination (IP address)? This API should be able to track relationships between multiple routing tables (specified by ip rules ).

+4
source share
2 answers

There is no guarantee that the route is static. If, for example, you are a ping host halfway around the world, one ping can travel one route, and the next ping can go on a completely different route. Even if you like traceroute (start at TTL 0 and increment by one for each answer), there is no guarantee that the route will not change from one packet to another.

The reason is because you cannot know what is happening with the exchange of data between the two routers from you to your destination. The router may answer once, but after a second there may be a power outage, or the cable may be disconnected, or for some other reason the network may be disconnected (my favorite is to clean the eject plugs because they need an outlet for their vacuum )

+1
source

A general purpose OS will always forward packets to the router to which it is connected. However, if the operating system is an OS router (e.g., iOS, Junos, etc.), it will search the routing table (among other things) to determine the next step. Packets usually originate from the end host, and then pass through a series of routers, and finally end at another endpoint.

I think you are looking for something like traceroute that can tell you the route that the packet will take.

0
source

All Articles