19

How can I determine the IP route taken for a specific IP destination (without looking at "route print" and figuring it out manually)?

In OS X there's route get 1.2.34 and in Linux there's /sbin/ip route get 1.2.3.4. Is there anything like that on Windows?

7

Yep. Open a command line and type tracert 1.2.3.4

  • Heh, good point. Not an optimal solution, since it does query the network for something you know locally, but for the most part, gives me the information I need. – Ilya Oct 13 '11 at 23:17
  • 1
    @Ilya: Using -d (no resolve IP) and -w 0 (don't wait for ping) should speed up the scan a lot. – Hello71 Oct 14 '11 at 0:30
  • 16
    This doesn't really do the same thing. The route get commands the original posted mentions perform a lookup in the local routing table and return the result. For example, you can ask ip route get 192.168.1.32/28 to find which routing table entry will be used for that network, but you can't ask tracert about network blocks. – larsks Nov 4 '12 at 3:31
  • 1
    @Hello71 -w 0 is not working in my case (gives error Bad value for option -w.). -w 1 works however. – KrishPrabakar May 7 '15 at 9:14
  • 7
    This is not the correct answer. tracert doesn't give the routing information such as which interface is being used. – RickMeasham Aug 1 '16 at 1:20
18

In Powershell:

Find-NetRoute -RemoteIPAddress "10.0.0.34" | Select-Object ifIndex,DestinationPrefix,NextHop,RouteMetric -Last 1

ifIndex DestinationPrefix NextHop     RouteMetric
------- ----------------- -------     -----------
     49 10.0.0.0/24       10.64.130.4           0
  • 2
    tbh this should be upvoted more. Find-NetRoute is probably the closest you're going to get to ip route get on Windows. – Bratchley Jun 20 '17 at 17:56
  • Note that this will not work on Windows 7 (and lower). Should work on Windows 8 (and above). – Nux Jul 23 '18 at 12:47
5

The pathping command is similar to tracert but includes the outgoing interface.

Using cygwin, this command gives the outgoing IP/interface for a particular destination (specified by $HOST):

pathping -n -w 1 -h 1 -q 1 $HOST | head -n 4 | tail -n 1 | awk '{print $2}'

  • 1
    This is a better answer. pathping -n -w 1 -h 1 -q 1 $HOST was also very informative for me. Helped me figure out a problem I was having. – jenming Feb 27 '17 at 5:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.