On Windows, how to determine route for IP destination?
79,064
Solution 1
Yep. Open a command line and type tracert 1.2.3.4
Solution 2
In Powershell:
Find-NetRoute -RemoteIPAddress "10.0.0.34" | Select-Object ifIndex,InterfaceAlias,DestinationPrefix,NextHop,RouteMetric -Last 1
ifIndex : 10
InterfaceAlias : Ethernet 2
DestinationPrefix : 10.64.0.0/10
NextHop : 0.0.0.0
RouteMetric : 0
Solution 3
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}'
Related videos on Youtube
Author by
Priya
Updated on September 18, 2022Comments
-
Priya almost 2 years
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?-
arana over 7 yearsif you are willing to use Powershell you can use the Get-NetRoute cmdlet, technet.microsoft.com/en-us/library/hh826126.aspx
-
-
Priya over 12 yearsHeh, 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.
-
JJ_Australia over 12 years@Ilya: Using
-d
(no resolve IP) and-w 0
(don't wait for ping) should speed up the scan a lot. -
larsks over 11 yearsThis 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 askip route get 192.168.1.32/28
to find which routing table entry will be used for that network, but you can't asktracert
about network blocks. -
KrishPrabakar about 9 years@Hello71
-w 0
is not working in my case (gives errorBad value for option -w.
).-w 1
works however. -
RickMeasham almost 8 yearsThis is not the correct answer.
tracert
doesn't give the routing information such as which interface is being used. -
jenming over 7 yearsThis 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. -
Bratchley about 7 yearstbh this should be upvoted more.
Find-NetRoute
is probably the closest you're going to get toip route get
on Windows. -
Nux almost 6 yearsNote that this will not work on Windows 7 (and lower). Should work on Windows 8 (and above).
-
cyfdecyf over 4 yearsThis should be the accepted answer. Btw, powershell seems not designed for daily interactive use ...