Static routes are used to define specific paths for network traffic to follow, rather than relying on the default routing behavior determined by the routing table. In some cases, you may need to add persistent static routes to ensure that network traffic between specific subnets or hosts is always directed through a particular gateway.
In this short guide, we will show you how to add persistent static routes in Windows.
Step 1: Open Command Prompt as Administrator
To add a persistent static route, you will need to run the Command Prompt as an administrator. Click the Start button, search for “cmd” or “Command Prompt”, right-click on the Command Prompt result, and select “Run as administrator”.
Step 2: Determine the Interface Index
Before adding the static route, you need to determine the interface index of the network adapter through which the traffic should be routed. In the Command Prompt, run the following command:
netsh interface ipv4 show interface
This command will display a list of network interfaces on your system, along with their interface index numbers. Note the index number of the interface you want to use for the static route.
Step 3: Add the Persistent Static Route
To add the persistent static route, use the route command with the following syntax:
route -p ADD <destination> MASK <subnet_mask> <gateway> METRIC <metric> IF <interface_index>
Replace <destination> with the target network or IP address, <subnet_mask> with the appropriate subnet mask for the destination, <gateway> with the IP address of the gateway through which the traffic should be routed, <metric> with a numerical value representing the route’s priority (lower values have higher priority), and <interface_index> with the interface index you noted in Step 2.
For example, to add a persistent static route for the 192.168.2.0/24 subnet through the gateway 192.168.2.1, with a metric of 1 and an interface index of 3, run:
route -p ADD 192.168.2.0 MASK 255.255.255.0 192.168.2.1 METRIC 1
The -p flag ensures that the route will persist across system reboots.
Step 4: Verify the Static Route
To verify that the static route has been added successfully, run the following command:
route print
This command will display the routing table, including the static route you just added. Check the “Persistent Routes” section to ensure that your new route is listed.
D:\>route print
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...01 56 57 d1 00 08 ...... VMware Virtual Ethernet Adapter for VMnet8
0x3 ...01 56 57 d1 00 01 ...... VMware Virtual Ethernet Adapter for VMnet1
0x4 ...10 22 49 h0 b7 a7 ...... Broadcom NetLink (TM) Fast Ethernet - Packet Sch
eduler Miniport
0x5 ...01 32 5e 3b gb 77 ...... Dell Wireless 1395 WLAN Mini-Card - Packet Sched
uler Miniport
0x10007 ...00 1h e1 de 27 gh ...... Bluetooth LAN Access Server Driver - Packet
Scheduler Miniport
===========================================================================
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.2.1 192.168.2.2 25
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.2.0 255.255.255.0 192.168.2.2 192.168.2.2 25
192.168.2.0 255.255.255.0 192.168.2.1 192.168.2.2 1
192.168.2.2 255.255.255.255 127.0.0.1 127.0.0.1 25
192.168.2.255 255.255.255.255 192.168.2.2 192.168.2.2 25
192.168.26.0 255.255.255.0 192.168.26.1 192.168.26.1 20
192.168.26.1 255.255.255.255 127.0.0.1 127.0.0.1 20
192.168.26.255 255.255.255.255 192.168.26.1 192.168.26.1 20
192.168.201.0 255.255.255.0 192.168.201.1 192.168.201.1 20
192.168.201.1 255.255.255.255 127.0.0.1 127.0.0.1 20
192.168.201.255 255.255.255.255 192.168.201.1 192.168.201.1 20
224.0.0.0 240.0.0.0 192.168.2.2 192.168.2.2 25
224.0.0.0 240.0.0.0 192.168.26.1 192.168.26.1 20
224.0.0.0 240.0.0.0 192.168.201.1 192.168.201.1 20
255.255.255.255 255.255.255.255 192.168.2.2 192.168.2.2 1
255.255.255.255 255.255.255.255 192.168.26.1 192.168.26.1 1
255.255.255.255 255.255.255.255 192.168.201.1 192.168.201.1 1
255.255.255.255 255.255.255.255 192.168.201.1 10007 1
255.255.255.255 255.255.255.255 192.168.201.1 4 1
Default Gateway: 192.168.2.1
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
192.168.2.0 255.255.255.0 192.168.2.1 1
Commands and Their Functions:
- netsh interface ipv4 show interface – Shows a list of network interfaces along with their interface index numbers.
- route -p ADD – Adds a persistent static route to the routing table.
- route print – Displays the current routing table, including static routes.
Conclusion
By adding static routes, you can ensure that network traffic between specific subnets or hosts is always directed through a particular gateway, improving the reliability and predictability of your network connections.
Please feel free to leave comments and suggest improvements to this guide. Your feedback is valuable and helps us improve our content for our audience.
Adding a static route in Microsoft Windows 10 or Server is done by using the route add command.
The following is the general syntax of the route add command we need to follow to add a permanent static route in Windows:
route add -p <destination> mask <subnet-mask> <gateway>
For example, the following route command tells the windows to add a new persistent route to the 192.168.1.0/24 network, using 10.0.0.1 as the gateway to reach the network.
route add -p 192.168.1.0 mask 255.255.255.0 10.0.0.1
When you want to add a static route to a single host, use the netmask 255.255.255.255.
For example, the following command adds a static route to the destination host 192.168.1.100 with the gateway address 10.0.0.1.
route add -p 192.168.1.100 mask 255.255.255.255 10.0.0.1
The most important part of the route add command is the -p option. Without the -p switch, our new route would not be persistent. It will disappear the next time you reboot your Windows PC/Server.
We can print the windows routing table using the route print command. Under the Persistent Routes header, you will see the list of permanent static routes.
Following is another static route example with a metric value:
route add -p 192.168.1.0 mask 255.255.255.0 10.0.0.1 metric 5
In case if you have more than one network interface, you could also specify the interface ID using the if command option.
route add -p 192.168.1.0 mask 255.255.255.0 10.0.0.1 if 1
When specifying the network interface, you have to provide the interface ID which you can find using the route print command.
Windows hold permanent static routes in the following registry
location: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servi.
ces\Tcpip\Parameters\PersistentRoutes
Static routes define fixed paths for network traffic that would otherwise have their path calculated automatically. This guide explains static routes, why you would use them, and provides step-by-step instructions showing how to add and remove static routes on Windows. It also looks at adding persistent routes and other tips for network management on Windows.
Get full control over your Windows networks with NinjaOne’s powerful endpoint management tools.
Try it for free.
What are static routes?
In computer networking, a “route” is the path network packets take to reach their destination. Data from your computer is broken into small packets for transfer over the local network (for example, between your computer and wireless printer), or for transmission over the internet (such as when you submit an online form). Network routing then takes care of making sure all of these packets reach their destination where they can be re-assembled into the original complete message.
Computer networks are designed in this way so that if there’s a disruption somewhere in the network, packets can be re-routed through a different connection. When there is no disruption, routing protocols can optimize for efficiency, sending data through different paths simultaneously to improve speed.
The key components in network routing are:
- Routing table: This is where each device (including your Windows PC) stores the information about the routes to different destinations.
- Next hop: Most network routes need to cover large distances over complex networks. The “next hop” is the next stop along the path to the destination (for example, there is a hop between your PC and a wireless printer — packets need to go first to your Wi-Fi router, then your printer).
- Routing protocols and metrics: Routing protocols are the software that is used by network devices to keep routing tables up-to-date with the latest paths data should take. This is done based on the number of hops, bandwidth, and/or latency.
Usually, routes are automatically calculated by the routing protocol and stored in a routing table based on routing metrics. These dynamic routes change based on network conditions. The default route can be set for all traffic with no route otherwise assigned in the routing table.
Static routes can be manually configured in a devices routing table, to set fixed paths traffic should take instead of dynamic routes or the default route. If this route is broken, traffic will not be able to reach the destination and a dynamic alternate route will not be calculated.
Why do you need to use static routes?
In some situations, the dynamic route is not the route you want specific traffic to take. You may want to take a known optimal route or send traffic along a secure connection. Example use-cases for static routes include:
- Sending traffic via a known reliable route that avoids faulty networking conditions that are outside your control or that fully utilizes a better connection for optimization.
- Building efficient networks using low-power devices that do not need to run routing protocols.
- Maintaining full control over the path network traffic takes for optimization or to ensure protected data only travels over your secure network infrastructure.
- Ensuring network traffic takes a predictable path for troubleshooting or easier management.
- Adding redundancy and resiliency to your networks by providing a known alternative path as a fallback to dynamic routes.
Static routes are frequently used to ensure certain traffic is sent over a VPN connection. This can be important when you handle sensitive data that you do not want routed over the internet. While static routes are usually not required for day-to-day tasks on home Windows PCs, there are situations where they are added for troubleshooting or to set up remote networks for work-from-home setups.
IP addresses and network masks
Route tables use the IPV4 or IPV6 IP address of the destination and hops to identify routes. You’ll need a basic understanding of IP addresses and network masks to write effective static routes.
How to use the route command for Windows
The route command is built-in to Windows and lets you view currently set static routes, as well as adding, removing, and editing them. The route command is available in all versions of Windows including Windows 11, Windows 10, and Windows Server. The route command can be run from either the Command Prompt or PowerShell, and needs to be run as an administrator.
To open PowerShell or the Command Prompt to use the route command, right-click on the Start menu, and then:
- Click Terminal (Admin) if you’re using Windows 11
- Click Command Prompt (Admin) if you’re using Windows 10
How to list static routes on Windows
To list the existing static routes, enter the following command:
route print
This will output the current route table, showing all the currently configured static routes. You can use this command to verify that you’ve successfully added, removed, or edited a static route.
How to add a static route on Windows
The below example route command adds a static route:
route add 0.0.0.0 mask 0.0.0.0 192.168.77.1
The command is constructed as follows:
- The route executable is called.
- The add command tells it to add a static route to the routing table.
- The first 0.0.0.0 is the destination network. In this case, 0.0.0.0 matches all networks.
- The second 0.0.0.0 specifies the subnet mask this static route should apply to, in this case again matching all subnets.
- 192.168.77.1 specifies the gateway address. This is the next hop through which all matching traffic will be sent.
This static route sends all network traffic to 192.168.77.1, effectively adding a default route.
The next example adds a route to a specific network:
route add 192.168.10.0 mask 255.255.255.0 192.168.77.1
The command differs from the previous example:
- 192.168.10.0 is the destination network.
- 255.255.255.0 specifies the subnet mask this static route should apply to, in this case matching all addresses in the 192.168.10.0 subnet.
- 192.168.77.1 specifies the gateway address. This is the next hop through which all matching traffic will be sent.
In effect, this static route sends traffic destined for the 192.168.10.0 network to 192.168.77.1.
How to remove a static route on Windows
To delete a static route, use the route delete command, and match the details with the static route you wish to delete.
route delete 0.0.0.0 mask 0.0.0.0 192.168.77.1
The above command deletes the static route created in the previous step.
How to remove all static routes on Windows
To delete all static routes on Windows, use the command:
route -f
Make a static route permanent/persistent on Windows
Static routes will be cleared from the route table on Windows when you reboot. To make a persistent route — one that is permanent and will survive a reboot — add the -p parameter to your route add command:
route -p add 0.0.0.0 mask 0.0.0.0 192.168.77.1
Troubleshooting and best practices for managing static routes
If you are manually managing static routes on Windows machines, you should document which routes are set on which machines to avoid a forgotten static route, causing a troubleshooting issue.
You should also regularly review which static routes are set (this can be done using the route print command in Windows), and remove ones that are no longer required. Network monitoring solutions will assist with identifying network changes and broken routes that may need to be addressed.
If you are working in an enterprise environment with multiple devices that all require the same static routes, you should implement them at the network level rather than per device.
Windows route management tools
In addition to the route command that is built into Windows, you can use the following tools to manage routes and perform other networking tasks on Windows:
- NetRouteView is a free routing utility for Windows that provides a graphical interface for viewing, adding, and modifying static routes.
- Angry IP Scanner and Advanced IP Scanner can help you find and identify devices on your local network, and manage static routes on connected Windows devices by executing remote commands or scripts.
Effortlessly manage your Windows networks with NinjaOne’s time-saving automations and comprehensive control over devices.
➤ Find out more.
Managing large Windows networks efficiently
If you need to manage static routes on a fleet of Windows devices, either on a single network or in bring-your-own-device (BYOD) scenarios with traveling or remote employees, you shouldn’t rely on manually adding static routes and other network configurations to individual devices.
The NinjaOne remote management and monitoring platform (RMM) helps you secure, manage, and monitor Windows devices at scale, ensuring that they are all correctly configured. This allows you to deploy updated networking and security policies from a centralized interface, removing the time-consuming tasks of updating, cataloging, and enforcing static routes and other policies.
Skip to content
Adding a static route to your Windows routing table is pretty easy.
Just use an elevated command prompt (Run as administrator-where needed) and type the following example:
route -p add 10.11.12.13 255.255.255.255 10.11.12.14 metric 3 if 2
The “-p” argument is important if you want your route to be here when you reboot (persistent). You should be familiar with arguments “metric” and “if” if you are using this commands. A good starting point is HELP for this command. Type “route add –help”.
To check your result type “route print” and it should be under “Persistent routes” section.
To remove or to delete an entry, type this: “route -p delete 10.11.12.13”
The “p” argument is also important as it concerns the Persistent Routes table, otherwise it would concern the first Active route table.
Another trick to check and edit your persistent routes is through the system registry.
In your regeditor follow this path:
HKEY_LOCAL_MACHINE->SYSTEM->CurrentControlSet->
->Services->Tcpip->Parameters->PersistentRoutes
After any change that includes your network connection check that its settings are not changed (i.e. gateway).
When you are editing your routes just be sure they are not on a remote machine because you could get easily cut off:)
Introduction
What is a Routing Table
A routing table indicates where will go the packets after leaving the system(PC, Server, Router, Switch. Firewall ..). The routing table in Windows does the same job. Determinate the best path to send the packets when will receive the packets from another source (PC, Server, ….)
In a big environment that they have multiple networks, it’s a very common practice to add routes for different networks or sometimes for specific IP Addresses. Always the decisions are taken based on the requirements that they have.
I will try to give you a very simple example.
We have a PC with two different Network Interfaces that are connected to different Networks. Because we can’t assign different gateways in each Interface we should leave one interface without a gateway.
In this case, we can route the packets from the interface without a gateway in the gateway that we want. So each time that we use the network that we have assigned in the interface without the gateway Windows will know where to send the packets.
How to view the routing table
Before proceeding with any change in the routing table or troubleshooting network issues you should view the routing table that already exists. As a best practice, it’s recommended to keep a note of the routing table before proceeding with any change.
You can type the following command to view the routing table. You will see a long list of network destinations and gateways. However, if you don’t have added a static route all the entries are created dynamically from the Windows.
You can see 3 different categories:
- IPv4 Route Table = List all the IPv4 dynamic routes that have been building from the windows.
- Persistent Routes = List all the static routes created by the IT Admins.
- IPv6 Route table = List all the IPv6 dynamic routes that have been building from the windows.
route print
How to add a static route
To add a static route on the routing table type the following command.
route add destination_network MASK subnet_mask gateway_ip_addres metric
Let’s explain one by one and give an example
- destination_network = From the network subnet that will receive the traffic
- subnet_mask= Is the subnet mask of the destination_network
- gateway_ip_address = The gateway that will pass the traffic.
- metric = It’s a value used by routing table to make a routing decision. This value is based on link speed, number of hops, and time delay. It’s optional.
Note
The static route that will be added manually, exists until the next restart of the PC/Server
How to add a persistent route
If we want to keep permanent the route then we need to add the option -p as in the example.
route add -p destination_network MASK subnet_mask gateway_ip_addres metric
This option will keep the route in the Persistent Routes of the routing table and will not deleted after a restart.
Let’s go to do an example with a very simple scenario
The scenario is the following:
We have one Laptop with a connection to a Local Network with a wired cable and a connection to Wi-fi.
We want to pass the traffic from the Local connection to our Local Network (Domain Controller, Fileserver …). However, we would like to connect to the Internet only from the Wi-fi connection.
The networks are
- 172.16.3.0/24 for the local network
- 192.168.137.0 for the Wi-fi connection
We will type the following command to route the traffic from the Local connection (wired cable) to the Local Network.
route add -p 172.0.0.0 MASK 255.0.0.0 172.16.3.254
Let’s explain the above command.
Because we have multiple VLANs in our network we say that any traffic that comes from the subnet 172.0.0.0 (which includes all the subnets that start with 172) routes to the gateway 172.16.3.254 which is the gateway of the Local connection.
Now let’s create the routing for the Wi-fi.
route add -p 0.0.0.0 MASK 0.0.0.0 192.168.137.254
Let’s explain the above command.
The following command routes all the traffic that isn’t matched to the subnets 172.0.0.0 with mask 255.0.0.0 to the gateway of the Wi-fi adapter.
Let’s take a look at the routing table to verify the routes
Type route print and check the Persistent Routes. We should see the new routes
After we have created and verified the routes in the routing table, we should verify that all work as expected.
Type the following command, and monitor the real-time connections of your machine.
netstat /f
Then open a Web page and check from where to send the requests.
Also, open a Remote desktop connection to an internal Server, and check from where the requests are sent.
If all are working as expected, the requests to the web page should be sent from 192.168.137.x, and the requests to the Remote desktop connections should be sent from 172.16.3.x
How to delete a static or persistent route
If we have created routes we would like to delete, we can replace the route add with the route delete.
Let’s see the example with the command.
route delete 0.0.0.0 MASK 0.0.0.0 192.168.137.254
The command for the route it’s very simple. However, you should have understood the traffic flow and what you want to achieve.
I hope to be valuable in this article.
See you next week.
