How to Add Persistent Static Routes in Windows

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.

See also  How to Install tcpdump

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.
See also  How to Setup and Configure Openfiler iSCSI Storage on VMware

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.

Comments

2 Comments

Leave a Reply

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