How to configure static routes to route traffic through a specific gateway

Use route /p add <destination> mask <netmask> <gateway> from an elevated Command Prompt to route traffic through an alternative gateway on Windows Server 2022, 2025, 2019, or Windows 11 (Windows 10 needs ESU). The /p flag makes it persistent; confirm with route print and verify with tracert. PowerShell’s New-NetRoute offers the same via NetTCPIP; unlike route add, it writes to both the active and persistent route stores by default, so no extra flag is needed for the route to survive a reboot.

Sometimes you may need to route traffic through a specific gateway only for destinations matching a group of IPs or a subnet.

Static routes are usually configured at the router level, but you can also configure them locally from the Windows command prompt. If you’re responsible for the router itself rather than just the Windows host, you may also want to look at how to configure Hot Standby Router Protocol (HSRP) on Cisco routers, so a single gateway failure doesn’t take down the path you’re about to set up. In our example we are using Windows Server 2022, but the same commands apply to any currently supported version of Windows – including Windows Server 2025, Windows Server 2019, and Windows 11. Windows 10 reached end of support on October 14, 2025: the commands below still work on Windows 10, but the OS itself no longer receives security updates unless the device is enrolled in the Extended Security Updates (ESU) program.

Viewing the current routing table

First of all, let’s view our routing table with the command route print:

C:\Windows\system32> route print
===========================================================================
Interface List
 12...00 0c 29 4a b2 e1 ......Intel(R) 82574L 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      192.168.0.1   192.168.0.10      25
        127.0.0.0        255.0.0.0         On-link       127.0.0.1     331
        127.0.0.1  255.255.255.255         On-link       127.0.0.1     331
  127.255.255.255  255.255.255.255         On-link       127.0.0.1     331
      192.168.0.0    255.255.255.0         On-link    192.168.0.10      281
     192.168.0.10  255.255.255.255         On-link    192.168.0.10      281
    192.168.0.255  255.255.255.255         On-link    192.168.0.10      281
        224.0.0.0        240.0.0.0         On-link       127.0.0.1     331
        224.0.0.0        240.0.0.0         On-link    192.168.0.10      281
  255.255.255.255  255.255.255.255         On-link       127.0.0.1     331
  255.255.255.255  255.255.255.255         On-link    192.168.0.10      281
===========================================================================
Persistent Routes:
  None
===========================================================================

We can see Internet traffic (identified by destination 0.0.0.0 and mask 0.0.0.0) is routed through the gateway 192.168.0.1, while the subnet 192.168.0.0/24 is directly connected (On-Link).

Creating a static route

Now it’s time to create a static route. We will send traffic directed to the IP address 1.1.1.1 through the alternative gateway 192.168.0.254.

We need to use the route command from an elevated CMD prompt (Run as Administrator). Here’s a description of the parameters:

  • Destination: specifies an IP address, a hostname, or a subnet
  • Mask: specifies the subnet mask associated with the route (defaults to 255.255.255.255 if not specified)
  • Gateway: specifies the IP address of the next-hop gateway
  • Metric: specifies an integer value for cost measurement (defaults to 1 if not specified)
  • Interface: specifies the interface used for the route (determined automatically from the gateway address if not specified)

In our example we run the command as follows:

route /p add  1.1.1.1 mask 255.255.255.255 192.168.0.254 

Making the route persistent

The /p parameter makes the route persistent: it is saved to the registry and survives reboots. Without /p, the route is lost when the machine restarts.

C:\Windows\system32> route /p add  1.1.1.1 mask 255.255.255.255 192.168.0.254 
 OK!

Verifying the new route

With another route print we can confirm that the static route has been added and verify its metric value relative to other routes:

C:\Windows\system32> route print
===========================================================================
Interface List
 12...00 0c 29 4a b2 e1 ......Intel(R) 82574L 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      192.168.0.1   192.168.0.10      25
          1.1.1.1  255.255.255.255    192.168.0.254   192.168.0.10       1
        127.0.0.0        255.0.0.0         On-link       127.0.0.1     331
        127.0.0.1  255.255.255.255         On-link       127.0.0.1     331
  127.255.255.255  255.255.255.255         On-link       127.0.0.1     331
      192.168.0.0    255.255.255.0         On-link    192.168.0.10      281
     192.168.0.10  255.255.255.255         On-link    192.168.0.10      281
    192.168.0.255  255.255.255.255         On-link    192.168.0.10      281
        224.0.0.0        240.0.0.0         On-link       127.0.0.1     331
        224.0.0.0        240.0.0.0         On-link    192.168.0.10      281
  255.255.255.255  255.255.255.255         On-link       127.0.0.1     331
  255.255.255.255  255.255.255.255         On-link    192.168.0.10      281
===========================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
          1.1.1.1  255.255.255.255    192.168.0.254       1
===========================================================================

The new entry 1.1.1.1 appears in Active Routes with metric 1 – lower than the default route’s metric of 25, confirming it will take priority for that specific destination. It also appears under Persistent Routes, confirming it will survive a reboot.

Using the tracert command we can verify that the static route is working and that traffic to 1.1.1.1 is indeed being forwarded through 192.168.0.254:

C:\Windows\system32> tracert 1.1.1.1
Tracing route to one.one.one.one [1.1.1.1]
over a maximum of 30 hops:
  1    <1 ms    <1 ms    <1 ms  192.168.0.254
  2     4 ms     4 ms     5 ms  203.0.113.1
  3     9 ms     9 ms    10 ms  1.1.1.1
Trace complete.

The first hop is 192.168.0.254, confirming that traffic is flowing through the alternative gateway as intended.

Removing a static route

You can delete the route at any time with:

C:\Windows\system32> route delete 1.1.1.1
 OK!

PowerShell alternative

For environments where routes need to be scripted or managed remotely, the NetTCPIP module provides the equivalent PowerShell cmdlets, available on all currently supported Windows versions. If you’re not yet comfortable with the shell, our Guide to PowerShell is a good place to start before working through the cmdlets below.

# View the IPv4 routing table
Get-NetRoute -AddressFamily IPv4

# Add a static route
# First, get the interface index with: Get-NetIPInterface
New-NetRoute -DestinationPrefix "1.1.1.1/32" -NextHop "192.168.0.254" -InterfaceIndex 12 -RouteMetric 1

# Remove a static route
Remove-NetRoute -DestinationPrefix "1.1.1.1/32" -Confirm:$false

Note that New-NetRoute requires the interface index (-InterfaceIndex), which you can retrieve beforehand with Get-NetIPInterface or Get-NetAdapter. For full parameter reference, see the official Microsoft documentation.

Frequently Asked Questions

How do I make a static route on Windows survive a reboot?

Add /p to the route add command, right after the gateway address — for example, route /p add 1.1.1.1 mask 255.255.255.255 192.168.0.254. This writes the route to the registry so it reloads every time TCP/IP starts. Without /p the route only lives in the active table and disappears at reboot. Check persistence with route print.

Should I use route add or New-NetRoute to add a static route?

Both do the same job. route add suits a quick, one-off route or troubleshooting on a single server. New-NetRoute, from the NetTCPIP PowerShell module, is better for remote management, scripting the same route across multiple machines, or fitting into a larger automation workflow — especially if you’re already scripting server configuration in PowerShell.

How do I remove a static route I no longer need on Windows?

From an elevated Command Prompt, route delete 1.1.1.1 removes both the active and, if set with /p, the persistent entry. In PowerShell, use Remove-NetRoute -DestinationPrefix “1.1.1.1/32” -Confirm:$false to skip the confirmation prompt. Either way, run route print or Get-NetRoute afterward to confirm the entry is actually gone.

Read related articles