29

I have the following problem: I have a server with a rather dynamic network configuration and need to configure routes on it with the IF parameter:

route add  ... mask ... ... if ?

Is there a reliable way, manual and or programmatical, to get that interface number if I know just about everything else about that adaptor?

4 Answers 4

40

You can see that info also when you run the route print command. It's the first thing displayed. The index is the first column

===========================================================================
Interface List
 13... ......Bluetooth Device (Personal Area Network)
 10... ......Intel(R) 82566MM Gigabit Network Connection
 11... ......Intel(R) Wireless WiFi Link 4965AG
 17... ......VMware Virtual Ethernet Adapter for VMnet1
 18. . ......VMware Virtual Ethernet Adapter for VMnet8
1
  • 1
    That number can change. Is there a way to either permanently set number to a device, or use other method that will always point to the same interface between boots? Dec 1, 2020 at 8:30
21

The following command displays the list of interfaces:

netsh int ipv4 show interfaces

3
  • 1
    This works but you should expound on your answer a little to make sure it isn't flagged.
    – TheCleaner
    Jan 15, 2015 at 14:10
  • This answer provides a little bit more "friendly" output then route print, but at the end they both do the job.
    – Sevenate
    Mar 2, 2020 at 7:23
  • This version is more compact than route print, +1 for me
    – jmd
    May 11, 2021 at 17:39
11

Since you know everything else about the adaptor, and since you are using Server 2008, you can (and should) just add your routes with netsh using the interface name:

netsh int ipv4 add route <remote netid>/<remote netmask> <interface name> <next hop>

Use of the route command is generally deprecated in 2008+.

3
  • I wouldn't say it is depreciated.. it's just more recommended to use netsh now. :) BTW, your command should be "netsh interface ipv4 add route"
    – Rex
    May 24, 2013 at 18:28
  • Yeah was moving too quickly, command edited:) While Microsoft rarely uses the term "deprecated", I believe their term was basically "It is recommended that netsh be used instead of route" moving forward. I've personally seen some issues with clusters when using the route command, in which routing problems occur on failover.
    – phoebus
    May 24, 2013 at 18:45
  • 3
    Note that the adatper name may be different from the one in route print and using the wrong name will result with the "helpful" error message: "The filename, directory name, or volume label syntax is incorrect.". use netsh interface ipv4 show interfaces to find the actual name.
    – ET-CS
    Mar 23, 2016 at 0:20
4

You can using PowerShell:

Get-WMIObject Win32_networkadapter | Select-Object Name, AdapterType, InterfaceIndex | Format-List
2
  • This returns numbers, but they don't match with the route print output. The DeviceID values also don't match. (And no, it's not simply an off-by-one issue.)
    – Jon Seigel
    Sep 24, 2015 at 15:31
  • According to the MS blog, the route command returns the adapter priority. This command returns the InterfaceIndex. see here: blogs.technet.microsoft.com/networking/2015/08/14/…
    – bobpaul
    May 25, 2018 at 16:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .