Linux Show Selected Route for Particular IP Address

Tags: April 8, 2014 11:11 AM

When having multiple gateway it is very useful know which route is used by particular address. So we can know if the routing is work as expected. For this task we can use ip route get command.

Show Selected Route for particular IP

ip route get 8.8.8.8
8.8.8.8 via 192.168.42.129 dev usb0  src 192.168.42.243 
    cache

Show Selected Route for particular Domain

The ip route does not do name resolution so we can use other tools such as dig to display routing for a domain.
ip route get "$( dig google.com +short | head -1 )"
74.125.135.100 via 192.168.42.129 dev usb0  src 192.168.42.243 
    cache  ipid 0x766e rtt 449ms rttvar 256ms cwnd 10
We need to pipe the result to "head" since the dig result might contains more than one address at a time.

Reference

Share on Facebook Twitter

0 comments:

Post a Comment