This is in unix environment. I have multiple routes in a host (visible with 'ip route show' command). If I am pinging an address, how can I find out which gateway was used to route the tracffic?

I tried using traceroute command, but it does not show the immediate gateway.

From below output, is my default gateway.

# ip r l dev front_eth1  proto kernel  scope link  src dev bond0  proto kernel  scope link  src
default via dev front_eth1  proto gated

When I do traceroute to an external address, the gateway used (default gateway is not shown in output.

# traceroute -n -I
traceroute to (, 30 hops max, 40 byte packets
 1  0.507 ms  1.008 ms  1.017 ms
 2  0.228 ms  0.233 ms  0.234 ms

Is there any option to view the same information as given by traceroute command, including the gateway used for routing?

migrated from stackoverflow.com Mar 12 '12 at 8:59

This question came from our site for professional and enthusiast programmers.


You can use the ip route get <address> command to ask the kernel to report the route it would use to send a packet to the specified address:

$ ip route get via dev eth0  src 
$ is my default route. If I ask for an address that would not go over the default route:

$ ip route get dev eth0  src 
  • Thaks a lot. :) That solves the issue. – divya Mar 12 '12 at 8:40
  • Random side question - If is "default route" or "gateway"... what name would be used to refer to ? Just "source" ? – dtmland Aug 2 '16 at 23:25
  • @sarnold, please confirm whether it needs internet on that server. – kd12 Jul 4 '17 at 7:31
  • @kd12 you only need an Internet connection on that server if you wish to route packets to the Internet. You can set up IP networks without being connected to the Internet if you wish; the routing tables don't know and don't care, it all works the same. :) – sarnold Jul 7 '17 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy