The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,768 other followers

Windows command-line: Finding default routes and setting their metric

Posted by jpluimers on 2014/03/23

When you have multiple network connections, sometimes you want to prefer one to be used as “default” (i.e. because it has higher speed or lower latency).

Windows already tries to accommodate for that by assigning “metrics” to your network connections. They depend on the kind of network (wired over wireless) and speed of the connection.

To see the current default network routes and their metrics, you use the route print command and filter it with findstr like this:

route print | findstr /C:"Metric" /C:""

The “” string is to filter out the default routes, and “Metric” includes the header line.

For one of my XP machines, the result is this:

Now, even though both metric are 10, my gateway is much slower than my gateway, so I want to prefer the last one.

(Note you can also use the command "route print" to give more detailed information including network interfaces).

You can change metrics from the Network Control Panel (ncpa.cpl) like this: Change the interface metric on a network adapter | Windows Reference.

But you can also do it from the command-line, as these posts show:

You’d think only one command will cut it:

route change mask metric 5

But it doesn’t: it will first delete the existing default routes, then add just the one you were changing:

Note: (learned the hard way) be very careful changing this over an RDP connection, as changing the network route can kill your connection because of the above reason (:

So the best is to change, then add:

route change mask metric 5
route add mask metric 10

Now I have the right routes:

To make the new routes persistent (so they get back after a reboot), just add the -p parameter like this:

route -p change mask metric 5
route -p add mask metric 10

After that, you will see them persisted with the route print command showed above:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: