Skip to content

How to Add and Remove Static Routes with PowerShell Print

  • 0

How to Add and Remove Static Routes with PowerShell

Applies to: Windows Server 2019, 2022 and 2025.

Static routes direct specific prefixes through a chosen next hop. A wrong route can black-hole management traffic or bypass security controls.

Network changes can immediately interrupt management access. Maintain console access, export the current configuration and use approved test addresses. Visit networkmanager.info for managed Windows VPS services.

Prerequisites

  • Maintain console access.
  • Record the current route table.
  • Identify interface index and next hop.
  • Confirm the remote prefix does not overlap local networks.

Procedure

Step 1: Inspect interfaces and routes

Capture baseline.

Get-NetIPInterface -AddressFamily IPv4
Get-NetRoute -AddressFamily IPv4 | Sort DestinationPrefix

Step 2: Test next hop

Confirm it is directly reachable.

Test-Connection 192.0.2.1 -Count 2

Step 3: Add persistent route

Replace TEST-NET values and interface index.

New-NetRoute -DestinationPrefix '198.51.100.0/24' -InterfaceIndex 12 -NextHop '192.0.2.1' -RouteMetric 50 -PolicyStore PersistentStore

Step 4: Test destination

Use route and application tests.

Test-NetConnection 198.51.100.20 -TraceRoute

Step 5: Check competing routes

Confirm longest-prefix and metric behaviour.

Verification

The route should use the intended interface and next hop.

Get-NetRoute -DestinationPrefix '198.51.100.0/24'
Test-NetConnection 198.51.100.20 -TraceRoute

Rollback

Remove-NetRoute -DestinationPrefix '198.51.100.0/24' -InterfaceIndex 12 -NextHop '192.0.2.1' after verifying console access.

Security and operational notes

Replace all example addresses. Persistent routes survive restart and must be included in configuration records.

Official references

Explore Netcloud24 Canada managed Windows Server hosting.


Was this answer helpful?

« Back