Add IPv6 address with Powershell

These steps will configure IPv6 on a network adapter using Powershell.

Adding an IPv6 address

  1. Make sure Powershell is launched with Administrator permissions.
  2. Get the ifIndex for the network adapter that you want to configure the IPv6 address on:
Get-NetAdapter -IncludeHidden | Sort-Object -Property ifIndex -Descending
Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
isatap.{CBDE325A-10DC-... Microsoft ISATAP Adapter                     13 Disconnected 00-00-00-00-00...       100 Kbps
Ethernet                  Microsoft Hyper-V Network Adapter            12 Up           00-15-5D-9B-83-02         4 Gbps
Local Area Connection* 9  Microsoft Kernel Debug Network Adapter       10 Not Present                             0 bps
Local Area Connection* 8  WAN Miniport (Network Monitor)                9 Up                                      0 bps
Local Area Connection* 7  WAN Miniport (IPv6)                           8 Up                                      0 bps
Local Area Connection* 6  WAN Miniport (IP)                             7 Up                                      0 bps
Local Area Connection* 5  WAN Miniport (PPPOE)                          6 Disconnected                            0 bps
Local Area Connection* 4  WAN Miniport (PPTP)                           5 Disconnected                            0 bps
Local Area Connection* 3  WAN Miniport (IKEv2)                          4 Disconnected                            0 bps
Local Area Connection* 2  WAN Miniport (SSTP)                           3 Disconnected                            0 bps
Local Area Connection* 1  WAN Miniport (L2TP)                           2 Disconnected                            0 bps

In this case we would like to add the IPv6 settings to the “Ethernet” adapter with ifIndex 10.

  1. Create the new IP address and optionally add the IPv6 gateway. You will need to set the correct ifIndex for your server:
New-NetIPAddress -InterfaceIndex 10 -IPAddress ffff::2 -PrefixLength 64 -DefaultGateway ffff::1

If you get an error at this step, make sure that IPv6 is enabled on the interface. The error I was getting looks like this:

New-NetIPAddress : Element not found.
    + CategoryInfo          : ObjectNotFound: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException
    + FullyQualifiedErrorId : Windows System Error 1168,New-NetIPAddress

You can check if IPv6 is enabled by using this command:

Get-NetAdapterBinding -DisplayName *6*

If the network adapter shows “Enabled” as false, you will need to enable it first (replace Ethernet with the NIC name):

Set-NetAdapterBinding -Name Ethernet -DisplayName *6* -Enabled $true
  1. Add the IPv6 DNS servers to use (optional):
Set-DnsClientServerAddress -InterfaceIndex 13 -ServerAddresses ("fd12:3456:ffff:1::1","fd12:3456:ffff:1::2")

Adding an IPv6 address with netsh

In case of CIM errors you may need to use netsh to add the IPv6 settings instead.

  1. Assign the IP address. You will need to set Ethernet to the name of the network adapter to add the IP address to.
netsh interface ipv6 add address Ethernet address=ffff:2/64
  1. Add the default gateway (optional). As above, you will need to set Ethernet to the name of the adapter:
netsh interface ipv6 add route ::/0 Ethernet ffff:1
  1. Add the IPv6 DNS servers to use (optional):
netsh interface ipv6 add dnsserver Ethernet fd12:3456:ffff:1::1
netsh interface ipv6 add dnsserver Ethernet fd12:3456:ffff:1::2

Leave a Reply

Your email address will not be published. Required fields are marked *