LLI Wiki — My Digital Knowledge Base

PowerShell: change the default gateway

Remove-NetRoute then New-NetRoute to move the default route to another interface.

Replace the default gateway of a Windows server with the NetTCPIP cmdlets: remove the default route from one interface and create it on another.

# Remove the default route on the management interface, then create it on the production interface
Remove-NetRoute -InterfaceAlias "Mgmt-Net" -NextHop "192.0.2.10"
New-NetRoute -InterfaceAlias "Prod-Net" -NextHop "192.0.2.11" -DestinationPrefix "0.0.0.0/0"

The same pattern applies to another environment with its own gateway:

Remove-NetRoute -InterfaceAlias "Mgmt-Net" -NextHop "192.0.2.10"
New-NetRoute -InterfaceAlias "Prod-Net" -NextHop "192.0.2.12" -DestinationPrefix "0.0.0.0/0"

Notes

Mastodon LLIMastodon SocialFosstodon