Adding Routes on Windows Servers

I’ll preface this post by saying I HATE host routes (not often that I capitalize words so you know how serious this is…) Lets face it, sometimes you need to add one to make an old and a new environment work, testing, VPN, B2B networks, etc. etc.

Windows has a basic, but in my opinion, a somewhat lousy command tool called “route” to add host routes. In it’s most basic form and under most circumstances you can use it right out of the box without any issues.

There are, however, those times when a server has three NIC’s, you need to add routes for different subnet masks, specific hosts, etc. That’s where things can get tricky.

I recently encountered an issue where even though we added a host route, it did not work. I knew something was wrong because when I captured traffic on the firewall that was the gateway for the route, I just didn’t see anything. Here’s the scenario; I am on the 10.100.1.0 subnet with 10.100.1.1 as my default server gateway. I need to talk to 10.100.2.50 but through a different gateway.

The first thing I did was add a one-to-one host route:

route add -p 10.100.2.50 mask 255.255.255.255 10.100.1.2

Ok, so that’s it right? Nope. By default it assigns interface 1 to the route, which is the loopback interface. When I tried to ping that 10.100.2.50 host I never saw the traffic.

I had to run a route print to see what my interfaces were numbered as:

C:\Users\me>route print
=============================================================
Interface List
 17...00 50 46 84 00 13 ......vmxnet3 Ethernet Adapter #2
 14...00 0c c9 0d d2 da ......vmxnet3 Ethernet Adapter #1
 1...........................Software Loopback Interface 1
=============================================================

Ok, so ethernet Adapter 1 is the one I want to use, which is interface 14, so I need to adjust my route statement.

route add -p 10.100.2.50 mask 255.255.255.255 10.100.1.2 if 14

Nice! My traffic works now.

Why do I think the route command is lousy? Well, because when I add a route for a /24 subnet, it works 90% of the time, but when I add a specific host (/32) route, I have to specify the interface. For example:

route add -p 10.100.2.0 mask 255.255.255.0 10.100.1.2

This command normally would work without specifying any interfaces. Why? I have no idea, maybe some Microsoft employees can fill me in.

The other issue I have is the inability to ping using a different gateway. I can ping using a different IP on that host with the ping -S command, but there is no way for me to test a ping without messing about with routes until I see what I need on my firewall. I would love it if I could ping -G and use a gateway IP to send traffic. Alas, I am getting off topic…

Adding Routes on Windows Servers