On a multihomed Linux machine, how can I find out what network interface will be used to send a packet to a specific host? I need to do this programmatically and I'd rather not parse and interpret the routing table myself.
On a multihomed Linux machine, how can I find out what network interface will be used to send a packet to a specific host? I need to do this programmatically and I'd rather not parse and interpret the routing table myself.
Use
ip route
for this. For instance:Shorter option:
Yes, as Michael Hampton suggests, use
ip route
. If you only want the interface, use thisFor example: