Search

How to configure IPv4 address Windows 2022 using PowerShell

Follow below steps to configure IPv4 address and other TCP/IP settings, Default Gateway address and DNS Server addresses, in Windows Server 2022, using PowerShell cmdlets.

Step 1 - You must run PowerShell as administrator, to configure IPv4 address in Windows Server 2022. To run PowerShell as administrator, create a Power Shell shortcut on your Windows Server desktop, right-click the PowerShell shortcut icon and then select "Run as administrator", as shown below.

new-ipv4-address-powershell-windows-2022-runas-01.jpg

 

If you using a ServerCore based server, there is no desktop to create PowerShell shortcut. In ServerCore based server, use "runas" commmand from cmd or PowerShell, to run PowerShell as administrator. Enter the password of administrator, when prompted.

new-ipv4-address-powershell-windows-2022-runas-02.jpg

Step 2 - Now we need to identify the InterfaceIndex number of the network adapter, where you are going to configure IPv4 address. Use Get-NetAdapter PowerShell cmdlet as shown below to get the InterfaceIndex number of the network adapter where you want to configure IPv4 address.


Get-NetAdapter | Format-List

 

new-ipv4-address-powershell-windows-2022-get-netadapter.jpg

There can be many network adapters in a computer. As you can see from above output, the InterfaceIndex number is 3. We need to properly identify the network adapter and note it’s InterfaceIndex number. Every time when a PowerShell cmdlet related with this network adapter is run, we need to provide this number.

Step 3 - Once we had identified the network adapter and its InterfaceIndex number, we can use PowerShell "New-NetIPAddress" cmdlet to configure a new IPv4 address and Default Gateway address. You can see from the below PowerShell cmdlet, you need to provide InterfaceIndex number when you run the cmdlet, to identify the network adapter.

From the below cmdlet, you can understand that the IPv4 address we are configuring now is 192.168.10.203, subnet mask is 255.255.255.0 (-PrefixLength 24) and Default Gateway address we are configuring is 192.168.10.1. Change it as per your requirement.


New-NetIPAddress -InterfaceIndex 3 -IPAddress 192.168.10.203 -PrefixLength 24 -DefaultGateway 192.168.10.1

 

new-ipv4-address-powershell-windows-2022-new-netipaddress.jpg

Step 4 - Now we have configured a new IPv4 address and Default Gateway address for the network adapter with InterfaceIndex number 3. To check whether the IPv4 address is configured properly, use PowerShell "Get-NetIPAddress" cmdlet as shown below.


Get-NetIPAddress -InterfaceIndex 3 -AddressFamily IPv4

 

new-ipv4-address-powershell-windows-2022-get-netipaddress.jpg

From the above cmdlet output, we can see that the IPv4 address configured is 192.168.10.203. Now, to check whether Default Gateway address is configured properly, use "Get-NetRoute" command as shown below.


Get-NetRoute -InterfaceIndex 3 -AddressFamily IPv4 -DestinationPrefix "0.0.0.0/0"

new-ipv4-address-powershell-windows-2022-get-netroute.jpg

From the above cmdlet output, we can see that the Default Gateway address configured is 192.168.10.1.

Step 5 - Last TCP/IP setting we are going to configure is DNS server addresses. Use "Set-DnsClientServerAddress" PowerShell cmdlet to configure DNS Server addresses, as shown below.


Set-DnsClientServerAddress -InterfaceIndex 3 -ServerAddresses 8.8.8.8, 8.8.4.4  

 

new-ipv4-address-powershell-windows-2022-set-dnsclientserveraddress.jpg

Step 6 - To check whether the DNS Server addresses are configured properly, use PowerShell "Get-DnsClientServerAddress" cmdlet as shown below.


Get-DnsClientServerAddress -InterfaceIndex 3 -AddressFamily IPv4

 

new-ipv4-address-powershell-windows-2022-get-dnsclientserveraddress.jpg

Written by Jajish Thomas.
Last updated on 9thnd April, 2022.
Related Tutorials
Introduction to Windows Server 2022
New features of Windows Server 2022
Hardware requirements for Windows Server
Different editions of Windows Server 2022
Difference between Server Core and Server with Desktop experience (GUI)
How to install Windows 2022 Server
How to use search functionality in Windows Server 2022
How to hide or unhide search box
How to add This PC icon to desktop in windows 2022
How to add Network icon to desktop in windows 2022
How to rename computer name in Windows 2022
How to rename computer name using PowerShell
How to configure IPv4 Address in Windows 2022
How to configure IPv6 Address in Windows 2022
How to configure IPv4 address Windows 2022 using PowerShell
How to configure IPv6 address Windows 2022 using PowerShell
How to shut down or restart Windows 2022
How to sign out from Windows Server 2022
How to run a program or app as administrator