question

RobertSocha-2099 avatar image
0 Votes"
RobertSocha-2099 asked RandallFalting-6133 answered

Setting rfc3021 IP address via powershell

Hi,

We are using RFC3021 compatible IP subnets (ie. /31 or /32). Hosts are directly connected to routers via L2 separation layer.

For example subnet: 192.168.1.2/31

GW: 192.168.1.2
HOST: 192.168.1.3
MASK: 255.255.255.254

Windows OS's do not suppport RFC3021 officialy. For example DHCP client dosen't work with the above subnet:

13635-nodhcp31.png

But setting this IP statically with changed subnet/prefix to 255.255.255.255 (/32) works from Windows Server 2008 to Windows Server 2019.
(I call this on-link setup - same as in Linux world).


Setting this example address via netsh - no problem:

13687-netsh31.png


Setting this same address via UI - with warning, but no other problems:

13732-winui-ip31.png

Result after hitting "Yes":

13659-winui-ip31-2.png

But setting this address via PowerShell (with prefix 31):

New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.1.3 -PrefixLength 31 -DefaultGateway 192.168.1.2 -InterfaceAlias "Internet"
New-NetIPAddress : The parameter is incorrect.
At line:1 char:1
+ New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.1.3 -PrefixLe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException
+ FullyQualifiedErrorId : Windows System Error 87,New-NetIPAddress

or with prefix 32:

New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.1.3 -PrefixLength 32 -DefaultGateway 192.168.1.2 -InterfaceAlias "Internet"
New-NetIPAddress : DefaultGateway 192.168.1.2 is not on the same network segment (subnet) that is defined by the IP address 192.168.1.3 and PrefixLength 32.
At line:1 char:1
+ New-NetIPAddress -AddressFamily IPv4 -IPAddress 192.168.1.3 -PrefixLe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException
+ FullyQualifiedErrorId : Windows System Error 87,New-NetIPAddress


Both trigger above errors.

I tried to use "-ErrorAction" to "force" this configuration - but no success.


My question is: could this address be setup via powershell? Or is it not supported? (two other configuration interfaces work OK)


Best regards

windows-server-powershell
nodhcp31.png (13.5 KiB)
netsh31.png (22.9 KiB)
winui-ip31.png (32.0 KiB)
winui-ip31-2.png (18.2 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MarcoShaw-2819 avatar image
2 Votes"
MarcoShaw-2819 answered

You could definitely file a bug, but that could take weeks/months to fix in the code. I'd recommend simply using netsh in your PowerShell script/code.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RandallFalting-6133 avatar image
0 Votes"
RandallFalting-6133 answered

It doesnt seem to matter what the prefix is, it seems that the default gateway is the cause. I still get:
New-NetIPAddress : DefaultGateway 192.168.254.2 is not on the same network segment (subnet) that is defined by the IP address 5.5.5.5 and PrefixLength 24.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.