What the difference between new-netroute and route add?

2

I have Windows Server 2012R2 with VPN Server (RRAS)

When some user connected I want setup routing to his network.

Everything work fine when I use route add, but when I use New-NetRoute routing don't works as needed.

For example (networks 192.168.110.0/24 and 192.168.111.0/24. both accessible via connection when I use route add command)

PS C:\tools> Get-NetRoute
ifIndex DestinationPrefix                              NextHop                                  RouteMetric PolicyStore
------- -----------------                              -------                                     ----------- -----------
22      192.168.111.0/24                               192.168.99.199                                     1 ActiveStore
22      192.168.110.0/24                               192.168.99.199                                     1 ActiveStore

Routing to network 192.168.110.0/24 was added with command

route add 192.168.110.0/24 192.168.99.199

Routing to network 192.168.111.0/24 was added with command

New-NetRoute -DestinationPrefix 192.168.111.0/24 -NextHop 192.168.99.199 -PolicyStore ActiveStore -RouteMetric 1 -InterfaceIndex 22

When I trying to ping host on network I receive next output:

PS C:\tools> ping 192.168.110.1 -n 1

Pinging 192.168.110.1 with 32 bytes of data:
Reply from 192.168.110.1: bytes=32 time=61ms TTL=63

Ping statistics for 192.168.110.1:
    Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 61ms, Maximum = 61ms, Average = 61ms
PS C:\tools> ping 192.168.111.1 -n 1

Pinging 192.168.111.1 with 32 bytes of data:
General failure.

Ping statistics for 192.168.111.1:
    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

So when I use route add I have no problems and everything works as needed, but when I use New-NetRoute I have problems with General failure error.

igor.kuzuro

Posted 2018-09-06T05:47:13.993

Reputation: 21

route add adds the route to IP stack routing table. New-NetRoute (it seems) adds the route to RRAS table. Check does the route added via New-NetRoute is visible in cmd - route print output... – Akina – 2018-09-06T06:43:41.373

@Akina: Hmm, so how do you add live IP routes via PowerShell cmdlets? – user1686 – 2018-09-06T07:04:54.713

I have detected those "difference" (routes addition via route add and via MMC-RRAS) when Windows Server 2000 was the most recent OS. From that time I do not use routing table edition other than route.exe - I like when I can predict the result. – Akina – 2018-09-06T07:23:08.683

@Akina output of route print same for both routes and route added via New-NetRoute is visible with route print. – igor.kuzuro – 2018-09-06T21:14:03.630

@grawity I also saw this problem a couple of years ago... but now time to play with this problem again. Concerning how to add live IP routes via PowerShell cmdlets... just use call to route.exe... I do it this way. – igor.kuzuro – 2018-09-06T21:20:36.160

Answers

0

according to the published docs...

New-Net​Route Creates a route in the IP routing table.

Description

The New-NetRoute cmdlet creates an IP route in the IP routing table. Specify the destination prefix, and specify an interface by using the interface alias or the interface index.

IP routing is the process of forwarding a packet based on the destination IP address. Routing occurs at TCP/IP hosts and at IP routers. The sending host or router determines where to forward the packet. To determine where to forward a packet, the host or router consults a routing table that is stored in memory. When TCP/IP starts, it creates entries in the routing table. You can add entries either manually or automatically.

Syntax

New-NetRoute [-DestinationPrefix] [-AddressFamily] [-CimSession] [-NextHop] [-PolicyStore] [-PreferredLifetime] [-Protocol] [-Publish] [-RouteMetric] [-ThrottleLimit] [-ValidLifetime] [-InterfaceAlias] [-Confirm] [-WhatIf] []

New-NetRoute [-DestinationPrefix] [-AddressFamily] [-CimSession] [-NextHop] [-PolicyStore] [-PreferredLifetime] [-Protocol] [-Publish] [-RouteMetric] [-ThrottleLimit] [-ValidLifetime] [-InterfaceIndex] [-Confirm] [-WhatIf] []

# Examples
# Example 1: Add an IP route to the routing table


New-NetRoute -DestinationPrefix "10.0.0.0/24" -InterfaceIndex 12 -NextHop 192.168.0.1
Get-NetRoute | Format-List -Property *

This example adds a routing table entry, and then displays the properties of all the entries in the routing table.

The first command creates a route for the destination prefix 10.0.0.0/24 for the interface that has the index of 12. The command specifies 192.168.0.1 as the next hop.

https://docs.microsoft.com/en-us/powershell/module/nettcpip/new-netroute?view=win10-ps

In computing, route is a command used to view and manipulate the IP routing table in both Unix-like and Microsoft Windows[1] operating systems. Manual manipulation of the routing table is characteristic of static routing.

In Linux distributions based on 2.2.x Linux kernels, the ifconfig and route commands are operated together to connect a computer to a network, and to define routes between computer networks. Distributions based on later kernels have deprecated ifconfig and route, replacing them with iproute2.

https://en.wikipedia.org/wiki/Route_(command)

So, you are reporting that is not what is happening? If so, it needs to be submitting to the MS PS GitHub as an issue / bug.

https://github.com/PowerShell/PowerShell/issues

postanote

Posted 2018-09-06T05:47:13.993

Reputation: 1 783