One of the features of Windows PowerShell is Route management, which is performed by the Get-NetRoute and New-NetRoute commands. Routing management in the CMD environment is with the Route command. In this article, we will teach you routing tutorial with PowerShell so that you can use PowerShell for routing in Windows.
Routing tutorial with PowerShell
PowerShell’s application for routing has many capabilities, and its many parameters will help you to easily get comprehensive information by personalizing the search.
Learn how to work with the Get-NetRoute command
This application is one of the routing commands in PowerShell that allows you to get complete information about the status of the routers written in your Windows. Here are some examples to teach you how to do this.
Get a list of routes associated with a network interface
Get-NetRoute -Protocol local -InterfaceAlias Ethernet
Get routes that point to network address 192.168.0.0
Get-NetRoute -DestinationPrefix 192.168*
Note: The network address must be entered as above. If you use an address such as 192.168.0.0, you will encounter an error.
List of routes added with a specific protocol
Get-NetRoute -Protocol Local -DestinationPrefix 192.168.*
In this command, you can use protocols such as Rip, bgp, Eigrp, etc. instead of Local.
Get a list of active routes
Get-NetRoute -State Alive
With the above command, you can get complete information from the written routines. You can use the Get-Help Get-NetRoute command for more information on other parameters.
Route writing tutorial with PowerShell
You can use the New-NetRoute command to write a Route manually. This command has the same structure as the Get-NetRoute command. In the following, we will give an example of how to write rout in PowerShell and explain the types of parameters on it.
Note: To write a route, you need to open PowerShell with Administrator access.
New-NetRoute -DestinationPrefix "10.0.0.0/24" -InterfaceAlias "Ethernet" -NextHop 192.168.1.1 -RouteMetric 1 -Protocol Local -Publish Yes
In the example above, a route for routing the network 10.0.0.0 is written along with some parameters, which we will explain below.
– DestionationPrefix: The desired network address along with its perfix for routing
– InterfaceAlias: The name of the interface you want to write route for
– NextHop: Gateway address to access the imported network
– RouteMetric: The priority of sending packets to the desired Gateway
– Protocol: The type of routing protocol
– Publish: Route running and activating
Now you will be able to write your desired rout.
Note: In the above command, you will need the 3 main parameters DestinationPrefix, InterfaceAlias and NextHop, and if other parameters are not written, Windows will set them by default.
Since PowerShell is the most powerful command line tool, most of the Windows Server management commands are done through this lovely blue environment. In this article, we tried to teach you how to get Get-NetRoute command, Get a list of routes associated with a network interface, List of routes added with a specific protocol, and so on.