In some moments it can be extremely useful add a static route to the routing table. In this article, we are going to explain how we can do it, it works on almost all versions of the operating system: Windows 7, 8, 10 and 11.

What are routing tables?

A routing table decides where all packets go when they leave a system, regardless of whether that system is a physical router or PC. The vast majority of routers, including the one built into our PC, use a dynamic routing method, where the router manages to select the best place to forward packets based on the information it gets from other routers.

Many routers provide the ability to add a static route (which is not dynamically updated) this is useful when we want to always forward certain traffic to a specific router or gateway. Why would we do this? Most people who use Windows won’t, even in business. But in some moments it can be something useful:

  • We have two connections. Perhaps we use one for regular use and the other to be in a work network. We want all traffic to a certain range of IP addresses to go out through one of these connections.
  • We set up multiple subnets on the network and we need to direct traffic to a specific subnet. Static routes are very useful in these environments.
  • When we use a Windows computer as a router for the network and we need to have more control over it.
YOU CAN ALSO READ:   How to get out of incognito mode in Chrome, Firefox and Edge

View Windows routing table

The first thing we need to see is the routing table. For this we are going to start Command Prompt by pressing Windows + X and then selecting the Command Prompt (administrator) option.

Route printing.

Once in the command prompt, we will have to write the following command: route print

Here we will see a fairly long list of network destinations and the gateways to which the packets are forwarded when they are directed to the destination in question. Unless we had added static routes, everything would be generated dynamically.

Add a static route to the Windows routing table

If we want to add a static route to the table, we will have to write a command using this syntax:

route ADD destination_network MASK subnet_mask gateway_ip metric_cost

In the case of subnet_mask and metric_cost they are optional. If we don’t specify a subnet mask; 255.255.255.0 will be used by default. In case we don’t specify a metric cost, the cost greater than the target input will be 0.0.0.0. The metric cost value is solely a cost relative to other costs in the table and is used with the system deciding between multiple paths that could reach the same destination.

For example, if we wanted to add a route specifying that all traffic destined for the 192.168.35.0 subnet went to a gateway at 192.168.0.2 and we only wanted to use the automatic metric cost, we could use the following command:

route ADD 192.168.35.0 MASK 255.255.255.0 192.168.0.2

If we use the route print command to look at the table now, we will see the new static route.

YOU CAN ALSO READ:   Solution to "We can't show Game Pass games" on Xbox

Obviously, all this is something simple, although we find a detail to consider. When we add a static route, by default it only lasts until the next time we start Windows. The reason for this is that many companies make use of a coordinated list of static routes that is updated regularly.

So instead of adding and updating all these paths on each machine, a batch script file is distributed that takes care of adding the newest paths during Windows startup. Thanks to this, the routing table is kept uncluttered.

We could use the batch script method, writing these scripts is also not an impossible task. But if we’re adding few routes above, we don’t expect to change often, we can just add the option to the command to make the route persistent. A persistent path is maintained even when Windows starts. We can use the command that we saw before, we will only make a small modification.

route -p ADD 192.168.35.0 MASK 255.255.255.0 192.168.0.2

Remove static route from Windows routing table

There may come a time where we want to get rid of a static route in the table. All we have to do is use this command: route delete destination_network

Therefore, to delete the route that we have created before with the destination network 192.168.35.0, we would only have to write the following command: route delete 192.168.35.0

Write A Comment