How to Add Static Route in Windows

Adding a static route to the routing table in Windows is simple.

Routing tables control what path a packet takes when it’s sent from a device. There are many devices that have routing tables and can control packet paths including computers, routers, firewalls, and even layer 3 switches.

Most modern networks use routing tables and technologies such as OSPF to dynamically update routing information and determine the best path for a packet to flow. Though, there are still situations where you might want a fixed or static route set on a device such as:

  • Multiple Internet connections, where you want traffic to specific destinations to flow over a particular connection
  • Multiple Subnets without something like OSPF where you need to manually direct traffic through your network
  • Using a Windows computer as your router
  • Having protected networks that you don’t want advertised in OSPF but still need to manage certain devices in remotely

In reality, there are lots of reasons and you should have a good one before you resort to playing around with the Windows routing table.

How to View the Windows Routing Table

It’s a good idea to take stock of your existing routing table before you make changes to it. To View the routing table:

  1. Open command prompt or PowerShell as an admin. Either right click on the Windows button in your taskbar or press Winodws Key + X and then click on Command Prompt (Admin) or Windows PowerShell (Admin). You can also search the start menu for Command Prompt or PowerShell and then right click on Command Prompt or PowerShell and click Run as Admin.
  2. At the prompt enter the following command and press enter:

route print

Which results in the following output:

PS C:\WINDOWS\system32> route print
===========================================================================
Interface List
16…c8 60 00 c2 be 82 ……Intel(R) 82579V Gigabit Network Connection
1………………………Software Loopback Interface 1
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.2.0.1 10.2.0.40 291
10.2.0.0 255.255.255.0 On-link 10.2.0.40 291
10.2.0.40 255.255.255.255 On-link 10.2.0.40 291
10.2.0.255 255.255.255.255 On-link 10.2.0.40 291
255.255.255.255 255.255.255.255 On-link 10.2.0.40 291
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 10.2.0.1 Default

You should see several entries in the routing table. If you haven’t added any static routes then what you’ll be seeing will be dynamically generated.

How to Add a Static Route to the Windows Routing Table

To enter a static route into the routing table you can use the following command:

route ADD dest_network MASK subnet_mask  gateway_address metric_cost

If you do not add a subnet mask the system will enter 255.255.255.0 into the routing table. If you don’t add a metric cost the system will increment the cost by 1 over the cost for the 0.0.0.0 destination entry.

The cost is essentially just a way for windows to pick a route when two routes could be used to reach the same destination. Windows will pick the lowest route that can reach the same place.

To use a practical example using the above command, if we wanted to add a route telling windows to use a gateway of 10.2.0.1 for the ipv4 address 10.3.0.25 we could enter the following command:

route ADD 10.3.0.25 MASK 255.255.255.255 10.2.0.1

Running the route print command from earlier we can see that entry is now in the routing table:

PS C:\WINDOWS\system32> route print
===========================================================================
Interface List
16…c8 60 00 c2 be 82 ……Intel(R) 82579V Gigabit Network Connection
1………………………Software Loopback Interface 1
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.2.0.1 10.2.0.40 291
10.2.0.0 255.255.255.0 On-link 10.2.0.40 291
10.2.0.40 255.255.255.255 On-link 10.2.0.40 291
10.2.0.255 255.255.255.255 On-link 10.2.0.40 291
10.3.0.25 255.255.255.255 10.2.0.1 10.2.0.40 36
255.255.255.255 255.255.255.255 On-link 10.2.0.40 291
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 10.2.0.1 Default

There is one little gotcha with this command. This route will only stay in the routing table until Windows is rebooted. Once that happens the table is wiped of non-persistent routes. If we want the entry to stick to we need to append our above command with a -p for persistent like so:

route ADD dest_network MASK subnet_mask  gateway_address metric_cost -p

Which would look like the following using our above example addresses:

route ADD 10.3.0.25 MASK 255.255.255.255 10.2.0.1 -p

If you do a route print you’ll now see the route entry has moved to the Persistent Routes section of the output.

PS C:\WINDOWS\system32> route print
===========================================================================
Interface List
16…c8 60 00 c2 be 82 ……Intel(R) 82579V Gigabit Network Connection
1………………………Software Loopback Interface 1
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.2.0.1 10.2.0.40 291
10.2.0.0 255.255.255.0 On-link 10.2.0.40 291
10.2.0.40 255.255.255.255 On-link 10.2.0.40 291
10.2.0.255 255.255.255.255 On-link 10.2.0.40 291
10.3.0.25 255.255.255.255 10.2.0.1 10.2.0.40 36
255.255.255.255 255.255.255.255 On-link 10.2.0.40 291
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 10.2.0.1 Default
10.3.0.25 255.255.255.255 10.2.0.1 1

Why would you want any static routes to be non-persistent?

One example would be running a script at startup that adds routes to the table based on a network file that you can update periodically so you don’t have to update routes on every pc individually. I don’t see this often anymore, but it’s still a legitimate reason.

How to Remove a Static Route from the Windows Routing Table

If you ever need to remove a route from the Windows routing table you just need to enter the following command:

Route delete dest_network

Using our example IP that would look like:

Route delete 10.3.0.25

Doing another route print shows that route is now gone.

Hopefully this was a simple enough tutorial for you to follow and you’re now well on your way to getting your packets to their intended destination.

Recommended for You: Solarwinds Server & Application Monitor (SAM)

Know which applications are having issues in your environment before users complain? Know which systems are causing those problems? How about which servers are about to have problems like running out of space or memory?

Automate collection of data and alerting on your applications and servers with Solarwinds Server & Application Monitor so you have these answers.

Get insight into Active Directory, DNS, DHCP, and your Virtual environment without needing to mess with complex templates or knowing a single line of code.

Leave a Reply

Your email address will not be published. Required fields are marked *