How to search in Linux IP routing table?

I manipulated the Linux routing table with "route add" and "route del". Now, given IP, how can I find out (by typing some command) which gateway / device will it go through?

For example, if I run:

route add -net 192.57.66.0 netmask 255.255.255.0 dev eth0 

Is there a command that can tell me if I am at 192.57.66.42, it will go through eth0?

+8
routing
source share
2 answers

You should stop using online tools because you will not find the answer there. But for iproute:

 ip route add 192.57.66.0/24 dev eth0 ip route get 192.57.66.42 
+11
source share
 netstat -rn 

when you enter this command, the system prints a table:

Kernel IP Routing Table

 Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 

now all you have to do to figure out which packets go through eth0 is using the " longest prefix match " main.

+3
source share

All Articles