25

I am using the following command to add a route, but the metric isn't working the way I want it to. I want the route I am adding to have a lower cost.

    C:\Users\cboyle>route ADD 0.0.0.0 MASK 0.0.0.0  192.168.76.2 METRIC 3 IF 11
 OK!

C:\Users\cboyle>

Here is my routing table before the above command.

    Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\cboyle>route print
===========================================================================
Interface List
 11...00 1a 4d 84 48 22 ......Marvell Yukon 88E8056 PCI-E Gigabit Ethernet Controller
 15...08 00 27 00 40 a3 ......VirtualBox Host-Only Ethernet Adapter
  1...........................Software Loopback Interface 1
 12...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
 13...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0     192.168.76.1    192.168.76.40     20
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
     192.168.56.0    255.255.255.0         On-link      192.168.56.1    276
     192.168.56.1  255.255.255.255         On-link      192.168.56.1    276
   192.168.56.255  255.255.255.255         On-link      192.168.56.1    276
     192.168.76.0    255.255.255.0         On-link     192.168.76.40    276
    192.168.76.40  255.255.255.255         On-link     192.168.76.40    276
   192.168.76.255  255.255.255.255         On-link     192.168.76.40    276
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    306
        224.0.0.0        240.0.0.0         On-link      192.168.56.1    276
        224.0.0.0        240.0.0.0         On-link     192.168.76.40    276
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    306
  255.255.255.255  255.255.255.255         On-link      192.168.56.1    276
  255.255.255.255  255.255.255.255         On-link     192.168.76.40    276
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  1    306 ::1/128                  On-link
 15    276 fe80::/64                On-link
 15    276 fe80::49e3:31a5:5cc7:97ea/128
                                    On-link
  1    306 ff00::/8                 On-link
 15    276 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

C:\Users\cboyle>

Here it is after.

C:\Users\cboyle>route print
===========================================================================
Interface List
 11...00 1a 4d 84 48 22 ......Marvell Yukon 88E8056 PCI-E Gigabit Ethernet Controller
 15...08 00 27 00 40 a3 ......VirtualBox Host-Only Ethernet Adapter
  1...........................Software Loopback Interface 1
 12...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter
 13...00 00 00 00 00 00 00 e0 Microsoft ISATAP Adapter #2
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0     192.168.76.1    192.168.76.40     20
          0.0.0.0          0.0.0.0     192.168.76.2    192.168.76.40     23
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    306
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    306
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    306
     192.168.56.0    255.255.255.0         On-link      192.168.56.1    276
     192.168.56.1  255.255.255.255         On-link      192.168.56.1    276
   192.168.56.255  255.255.255.255         On-link      192.168.56.1    276
     192.168.76.0    255.255.255.0         On-link     192.168.76.40    276
    192.168.76.40  255.255.255.255         On-link     192.168.76.40    276
   192.168.76.255  255.255.255.255         On-link     192.168.76.40    276
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    306
        224.0.0.0        240.0.0.0         On-link      192.168.56.1    276
        224.0.0.0        240.0.0.0         On-link     192.168.76.40    276
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    306
  255.255.255.255  255.255.255.255         On-link      192.168.56.1    276
  255.255.255.255  255.255.255.255         On-link     192.168.76.40    276
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  1    306 ::1/128                  On-link
 15    276 fe80::/64                On-link
 15    276 fe80::49e3:31a5:5cc7:97ea/128
                                    On-link
  1    306 ff00::/8                 On-link
 15    276 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

C:\Users\cboyle>

I want the route that I am adding to have priority over the default one.

Corey
  • 1,943
  • 12
  • 38
  • 53

6 Answers6

13

This question is ancient, but if you stumbled across it like I did, try the following (confirmed on Win10);

open the adapter properties, IPv4 settings, Advanced, then...

Uncheck the "Automatic Metric" as mentioned previously, AND set an interface metric of some value (I used "10" for this example)

Click OK/Apply until you are back at the network connections. Disable and re-enable the adapter to reset everything and incorporate the new setting.

route print... You will now notice the default metric for the adapter has increased by 10 to 20.

add your new default route with a metric of "5" as mentioned previously

route print... it will be created as "15" vs the "20" of the existing default.

Dave
  • 231
  • 2
  • 2
11

My guess is that it's because of the Automatic Metric option set on the NIC. The automatic metric is based on the link speed so I'm guessing that your host is connected to a 100Mbps switch port. The DG will be assigned a metric based on the link speed alone. Any statically assigned route will be assigned a metric based on the link speed PLUS the metric you assign. If you want to assign a lower metric to your static routing table entry than the metric that's assigned to the DG, then disable the Automatic Metric option on the NIC.

http://support.microsoft.com/kb/299540

joeqwerty
  • 108,377
  • 6
  • 80
  • 171
  • 1
    I tried disabling "Automatic Metric" on the IP4 settings of the adapter, but still no change in behavior. The command I am using seems to work fine on Windows XP, but not on 7. – Corey Feb 24 '11 at 04:25
5

The relevant portion of the route /? help text:

     > route ADD 157.0.0.0 MASK 255.0.0.0 157.55.80.1 METRIC 3 IF 2
              destination^      ^mask     ^gateway     metric^    ^
                                                         Interface^

You can see here that you set this via the METRIC option when you add the route. Lower numbers take priority over higher numbers.

Based on the information you posted, it looks like it is assigning the metric relative to the chart found at this link: http://support.microsoft.com/kb/299540, or relative to the default gateway. You might see if it lets you use a negative value there to force a lower metric cost for your desired route.

Joel Coel
  • 12,910
  • 13
  • 61
  • 99
  • 3
    In the command I posted above, I have the METRIC set to 3, but it ended up being 23. Which dose not accomplish my goal. – Corey Feb 22 '11 at 15:45
  • @Corey did you read my last paragraph? – Joel Coel Feb 22 '11 at 16:44
  • 3
    just tried a negative value, but it threw an error – Corey Feb 24 '11 at 04:18
  • 8
    Old post but I had to downvote, negative value is useless and while it's true these metrics are being entered relative to the gateway, you don't offer any real advice or solution. – D3l_Gato Oct 14 '14 at 15:56
3

I know this is late but I just ran into this today - I wanted to connect to gmail but it was blocked from the Domain LAN Web Filter. I brought in a wifi usb to get to the non-domain network and was able to get to gmail by changing the priority of the traffic. This still allowed me to access the domain network as well.

To find out the interface #'s

   Route Print 

Use Netsh to set the lower value on the usb wifi device interface. The lower value means higher priority. This will remove the automatic setting as well.

netsh interface ipv4 set interface 25 metric=2

Use Route Print to verify

If you make a mistake you can turn the interface back to automatic

netsh interface ipv4 set interface 25 metric=automatic

For more about netsh see http://www.colorconsole.de/cmd/en/Windows_Vista/netsh/interface/ipv4/set/interface.htm

  • This works great. It requires an elevated cmd window, and you can also address an interface by name, i.e. `netsh int ip set interface interface="Ethernet" metric=121` `netsh int ip set interface interface="WiFi" metric=111` `netsh int ip set interface interface="Ethernet 2" metric=101` – Kurt Koller Apr 11 '18 at 21:16
  • Thanks very much for this answer. I'd like to add, we can use interface names instead of the 2 digit numbers, which can be found using this command `netsh interface show interface` – Shayan Nov 24 '20 at 09:52
  • I just want to speak on behalf of every IT professional on this site: Plugging your own wifi adapter or access point into a corporate-owned network is bad and you should not do it. It's a tremendous security risk, and beyond that it has the potential to bring down the entire network through DHCP interference, network loops, broadcast storms, and a host of other problems. Doing it with the *intentional* purpose of bypassing network security is even worse. If I caught someone doing this on my network I'd write a very strongly worded "Fire this person" e-mail to their manager. – Thomas Mar 11 '22 at 17:37
2

Based on my experience, using several identical routes with different metrics on Windows is tricky at best, and often unreliable, especially on Windows Vista/7. You can work around it by using two routes instead of one, thus forcing Windows to use the more specific routes. So, following your example:

route ADD 0.0.0.0 MASK 128.0.0.0 192.168.76.2 IF 11
route ADD 128.0.0.0 MASK 128.0.0.0 192.168.76.2 IF 11

This will accomplish your goal reliably. Actually, that's the solution used by the OpenVPN software to establish a default route over a VPN.

Etienne Dechamps
  • 2,164
  • 8
  • 24
  • 28
  • Currently it is VPN software that causes troubles for me. It added it's 192.168.*.* routes as a higher priority. Thus having a connected router via LAN you still can not address computers in this LAN. Win7 ROUTE's METRIC parameter completely sucks. – Askar Kalykov May 22 '13 at 08:32
0
  1. Disable "Automatic Metric" for the interface.
  2. Modify the default route increasing its metric route CHANGE 0.0.0.0 MASK 0.0.0.0 192.168.76.1 METRIC 2 IF 11.
  3. Create you own route with a lower metric route ADD 0.0.0.0 MASK 0.0.0.0 192.168.76.2 METRIC 1 IF 11.

Note: I haven't tested it.

Jaime Hablutzel
  • 416
  • 4
  • 10