Windows OS Hub / PowerShell / Configure Network Settings on Windows with PowerShell: IP Address, DNS, Default Gateway, Static Routes
![](http://paperhelp.pw/777/templates/cheerup2/res/banner1.gif)
Configure Network Settings on Windows with PowerShell: IP Address, DNS, Default Gateway, Static Routes
Managing network adapter settings via powershell, how to get an ip address settings with powershell, set static ip address on windows using powershell, set dns server ip addresses in windows with powershell, managing routing tables with powershell, powershell: change adapter from static ip address to dhcp, change dns and ip addresses remotely on multiple computers with powershell.
Previously, the netsh interface ipv4 command was used to manage network settings from the CLI. In PowerShell 3.0 and newer, you can use the built-in NetTCPIP PowerShell module to manage network settings on Windows.
To get the list of cmdlets in this module, run the following command:
get-command -module NetTCPIP
![change static ip address powershell Managing WIndows Network Settings with PowerShell NetTCPIP module](https://woshub.com/wp-content/uploads/2020/08/managing-windows-network-settings-with-powershell.png.webp)
List available network interfaces on a Windows computer:
Get-NetAdapter
The cmdlet returns the interface name, its state (Up/Down), MAC address, and port speed.
In this example, I have several network adapters on my computer (besides the physical connection, Ethernet0 , I have Hyper-V and VMWare Player network interfaces).
To display only enabled physical network interfaces:
Get-NetAdapter -Physical | ? {$_.Status -eq "Up"}
![change static ip address powershell Get-NetAdapter - list connected network adapters](https://woshub.com/wp-content/uploads/2020/08/get-netadapter-list-connected-network-adapters.png.webp)
You can view only certain network adapter parameters, such as name, speed, status, or MAC address:
Get-NetAdapter |Select-Object name,LinkSpeed,InterfaceOperationalStatus,MacAddress
![change static ip address powershell list nic mac address with powershell](https://woshub.com/wp-content/uploads/2020/08/list-nic-mac-address-powershell.jpg.webp)
Get-NetAdapter –IncludeHidden
You can refer to network interfaces by their names or indexes (the Index column). In our example, to select the physical LAN adapter Intel 82574L Gigabit Network Connection , use the command:
Get-NetAdapter -InterfaceIndex 8
![change static ip address powershell powershell Get-NetAdapter select NIC by name](https://woshub.com/wp-content/uploads/2020/08/powershell-get-netadapter-select-nic-by-name.png.webp)
You can change the adapter name:
Rename-NetAdapter -Name Ethernet0 -NewName LAN
To disable a network interface, use this command:
Enable the NIC by its name:
Enable-NetAdapter -Name Ethernet0
![change static ip address powershell Using PowerShell to disable a network adapter](https://woshub.com/wp-content/uploads/2020/08/using-powershell-to-disable-a-network-adapter.png.webp)
If the network adapter has a configured VLAN number, you can view it:
Get-NetAdapter | ft Name, Status, Linkspeed, VlanID
Here is how you can find out the information about the network adapter driver that you are using:
Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName
![change static ip address powershell list network adapter used drivers](https://woshub.com/wp-content/uploads/2020/08/list-network-adapter-used-drivers.png.webp)
List the information about physical network adapters (PCI slot, bus, etc.):
Get-NetAdapterHardwareInfo
Disable the IPv6 protocol for the network interface:
Get-NetAdapterBinding -InterfaceAlias Ethernet0 | Set-NetAdapterBinding -Enabled:$false -ComponentID ms_tcpip6
Disable the NetBIOS protocol for a network interface:
Set-NetAdapterBinding -Name Ethernet0 -ComponentID ms_netbios -AllBindings -Enabled $True
To get current network adapter settings in Windows (IP address, DNS, default gateway):
Get-NetIPConfiguration -InterfaceAlias Ethernet0
![change static ip address powershell Get-NetIPConfiguration - Retrieve the IP configuration on WIndows via PowerShell](https://woshub.com/wp-content/uploads/2020/08/get-netipconfiguration-retrieve-the-ip-configura.png.webp)
To display more detailed information about the network interface TCP/IP configuration, use the command
Get-NetIPConfiguration -InterfaceAlias Ethernet0 -Detailed
In this case, the assigned network location (profile) (NetProfile.NetworkCategory) of the interface, MTU settings (NetIPv4Interface.NlMTU), whether obtaining an IP address from DHCP is enabled (NetIPv4Interface.DHCP), and other useful information are displayed.
![change static ip address powershell Get-NetIPConfiguration detailed info](https://woshub.com/wp-content/uploads/2020/08/get-netipconfiguration-detailed-info.png.webp)
To get the IPv4 interface address only:
(Get-NetAdapter -Name ethernet0 | Get-NetIPAddress).IPv4Address
Return the value of the interface’s IP address only:
Display a list of the network protocols that can be enabled or disabled for a network adapter:
Get-NetAdapterBinding -Name ethernet0 -IncludeHidden -AllBindings
![change static ip address powershell Get-NetAdapterBinding view enabled network protocols](https://woshub.com/wp-content/uploads/2020/08/Get-NetAdapterBinding-enabled-network-protocols.jpg.webp)
Let’s try to set a static IP address for the NIC. To change an IP address, network mask, and default gateway for an Ethernet0 network interface, use the command:
Get-NetAdapter -Name Ethernet0| New-NetIPAddress –IPAddress 192.168.2.50 -DefaultGateway 192.168.2.1 -PrefixLength 24
You can set an IP address using an array structure (more visually):
$ipParams = @{ InterfaceIndex = 8 IPAddress = "192.168.2.50" PrefixLength = 24 AddressFamily = "IPv4" } New-NetIPAddress @ipParams
If a static IP address is already configured and needs to be changed, use the Set-NetIPAddress cmdlet:
Set-NetIPAddress -InterfaceAlias Ethernet0 -IPAddress 192.168.2.90
To disable obtaining an IP address from DHCP for your adapter, run the command:
Set-NetIPInterface -InterfaceAlias Ethernet0 -Dhcp Disabled
Remove static IP address:
Remove-NetIPAddress -IPAddress "xxx.xxx.xxx.xxx"
To set the preferred and alternate DNS server IP addresses in Windows, use the Set-DNSClientServerAddress cmdlet. For example:
Set-DNSClientServerAddress –InterfaceIndex 8 –ServerAddresses 192.168.2.11,10.1.2.11
You can also specify DNS nameserver IPs using an array:
$dnsParams = @{ InterfaceIndex = 8 ServerAddresses = ("8.8.8.8","8.8.4.4") } Set-DnsClientServerAddress @dnsParams
After changing the DNS settings, you can flush the DNS resolver cache (equivalent to ipconfig /flushdns ):
Clear-DnsClientCache
The Get-NetRoute cmdlet is used to display the routing table.
Get the default gateway route for a physical network interface in Windows:
Get-NetAdapter -Physical | ? {$_.Status -eq "Up"}| Get-netroute| where DestinationPrefix -eq "0.0.0.0/0"
![change static ip address powershell powershell: get default gateway route](https://woshub.com/wp-content/uploads/2020/08/powershell-get-default-gateway.jpg.webp)
To add a new route, use the New-NetRoute cmdlet:
New-NetRoute -DestinationPrefix "0.0.0.0/0" -NextHop "192.168.2.2" -InterfaceIndex 8
This command adds a permanent route to the routing table (similar to route -p add ). If you want to add a temporary route, add the -PolicyStore "ActiveStore" option. This route will be deleted after restarting Windows.
Remove a route from the routing table:
Remove-NetRoute -NextHop 192.168.0.1 -Confirm:$False
To configure your computer to obtain a dynamic IP address for the network adapter from the DHCP server, run this command:
Set-NetIPInterface -InterfaceAlias Ethernet0 -Dhcp Enabled
Clear the DNS server settings:
Set-DnsClientServerAddress –InterfaceAlias Ethernet0 -ResetServerAddresses
And restart your network adapter to automatically obtain an IP address from the DHCP server:
Restart-NetAdapter -InterfaceAlias Ethernet0
If you previously had a default gateway configured, remove it:
Set-NetIPInterface -InterfaceAlias Ethernet0| Remove-NetRoute -Confirm:$false
If you need to reset all the IPv4 settings for the computer’s network interfaces and switch them to obtain a dynamic IP address from DHCP, use the following script:
$IPType = "IPv4" $adapter = Get-NetAdapter | ? {$_.Status -eq "up"} $interface = $adapter | Get-NetIPInterface -AddressFamily $IPType If ($interface.Dhcp -eq "Disabled") { If (($interface | Get-NetIPConfiguration).Ipv4DefaultGateway) { $interface | Remove-NetRoute -Confirm:$false } $interface | Set-NetIPInterface -DHCP Enabled $interface | Set-DnsClientServerAddress -ResetServerAddresses }
You can use PowerShell to remotely change the IP address or DNS server settings on multiple remote computers.
Suppose, your task is to change the DNS settings on all Windows Server hosts in the specific AD Organizational Unit (OU) . The following script uses the Get-ADComputer cmdlet to get the list of computers from Active Directory and then connects to the remote computers through WinRM (the Invoke-Command cmdlet is used):
$Servers = Get-ADComputer -SearchBase ‘OU=Servers,OU=Berlin,OU=DE,DC=woshub,DC=cpm’ -Filter '(OperatingSystem -like "Windows Server*")' | Sort-Object Name ForEach ($Server in $Servers) { Write-Host "Server $($Server.Name)" Invoke-Command -ComputerName $Server.Name -ScriptBlock { $NewDnsServerSearchOrder = "192.168.2.11","8.8.8.8" $Adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne 'True' -and $_.DNSServerSearchOrder -ne $null} Write-Host "Old DNS settings: " $Adapters | ForEach-Object {$_.DNSServerSearchOrder} $Adapters | ForEach-Object {$_.SetDNSServerSearchOrder($NewDnsServerSearchOrder)} | Out-Null $Adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne 'True' -and $_.DNSServerSearchOrder -ne $null} Write-Host "New DNS settings: " $Adapters | ForEach-Object {$_.DNSServerSearchOrder} } }
Exchange Offline Address Book Not Updating in Outlook
How to run program without admin privileges and bypass uac prompt, related reading, how to copy/paste to ms word without losing..., check windows 11 hardware readiness with powershell script, create a multi-os bootable usb flash drive with..., read, modify, and parse json file (object) with..., configure dns scavenging to clean up stale dns....
Lovely like always! many thanks
Thanks for the great info. Would you happen to know a way to get the IP from the PC and then set the internet proxy using the 2nd octet from the IP address? So I have multiple schools and each has a proxy server, so I want to be able to set the proxy based on where that PC is. Location 1 gives PC IP address of 100.55.50.100, Proxy at this location is 100.55.100.1:9090 Location 2 gives PC IP address of 100.60.50.26, Proxy at this location is 100.60.100.1:9090 The second octet is what changes between locations for both proxy address and IP schema. I am trying to do a script at login for the user, so that if the device moves locations, it will not need to have the proxy manually re-entered to get back on the internet.
I think it will be easier for you to configure the Web Proxy Automatic Detection (WPAD) protocol or Proxy Auto-Configuration (PAC) file to automatically configure proxy setting on client computers.
Double thumbs up, well done.
Any Idea how to modify the Connection specific DNS suffix for a network adapter via powershell if possible?
Wow, amazing work! Was wondering if you know a way to set a static ip for a network adapter without it disconnecting UDP/TCP connections?
Hi, Could you or anyone help to create two scripts that:
script #1. Reads and records all IP settings for a NIC (IP-, subnet mask-, gateway-, and DNS addresses)
script #2. Changes the IP settings to the settings recorded by script 1
Script 1. Saves all network adapters settings to a json file: $adapterSettings = @() foreach ($adapter in $adapters) { $settings = Get-NetIPAddress -InterfaceIndex $adapter.InterfaceIndex $dns = Get-DnsClientServerAddress -InterfaceIndex $adapter.InterfaceIndex $adapterInfo = [PSCustomObject]@{ AdapterName = $adapter.Name IPAddress = $settings.IPAddress SubnetMask = $settings.PrefixLength Gateway = $settings.NextHop DNS = $dns.ServerAddresses } $adapterSettings += $adapterInfo } $adapterSettings | ConvertTo-Json | Out-File -FilePath "C:\PS\NIC_Settings.json"
Script 2: Apply network settings from file to NICs:
$adapterSettings = Get-Content -Raw -Path "C:\PS\NIC_Settings.json"| ConvertFrom-Json foreach ($adapterInfo in $adapterSettings) { Set-NetIPAddress -InterfaceAlias $adapterInfo.AdapterName -IPAddress $adapterInfo.IPAddress -PrefixLength $adapterInfo.SubnetMask Set-NetIPInterface -InterfaceAlias $adapterInfo.AdapterName -InterfaceMetric $null Set-DnsClientServerAddress -InterfaceAlias $adapterInfo.AdapterName -ServerAddresses $adapterInfo.DNS Set-NetRoute -InterfaceAlias $adapterInfo.AdapterName -NextHop $adapterInfo.Gateway } Restart-NetAdapter -Confirm:$false
Leave a Comment Cancel Reply
Notify me of followup comments via e-mail. You can also subscribe without commenting.
Current ye@r *
Leave this field empty
![change static ip address powershell](https://itluke.online/wp-content/uploads/2019/02/cropped-itluke_cloud_large-1.png)
Azure, Windows, Powershell, PKI, Security and more…
How to replace an existing static ip address with powershell.
Starting with Windows Server 2012, you can now handle directly the IP configuration with PowerShell cmdlets.
Unfortunately, there is no cmdlet which directly updates an already existing IP address. You have to use four of them.
Please be aware that you will disconnect yourself from the computer if you do this operation remotely. This won’t happen if you use PowerShell Direct or a VM console.
![change static ip address powershell change static ip address powershell](https://itluke.online/wp-content/uploads/2018/04/get-netipaddress_index.png?w=756)
- Ensure DHCP is disabled on this interface.
Otherwise, you will get an error message:
![change static ip address powershell change static ip address powershell](https://itluke.online/wp-content/uploads/2018/04/remove-netipaddress.png?w=756)
An explanation of the Automatic Metric feature for IPv4 routes (Microsoft Support)
IP Routing Table (Microsoft Technet)
Subnets and Subnet Masks (Microsoft Technet)
NetTCPIP cmdlets (Microsoft Docs)
Share this:
- Click to email a link to a friend (Opens in new window)
- Click to share on Twitter (Opens in new window)
- Click to share on LinkedIn (Opens in new window)
- Click to share on Reddit (Opens in new window)
- Click to share on Pocket (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on WhatsApp (Opens in new window)
- Click to print (Opens in new window)
3 thoughts on “ How to replace an existing static IP address with PowerShell ”
Thanks for the article!
I’ve tried this, but I run in to the following issue:
With the Get-Netipaddress -InterfaceIndex $adapterIndex | Remove-NetIPAddress -Confirm:$false
followed by New-NetIPAddress -IPAddress $ip -InterfaceIndex $adapterIndex -PrefixLength $subnet -DefaultGateway $gateway -AddressFamily IPv4
I get the following error: New-NetIPAddress : The object already exists. At line:373 char:9 + New-NetIPAddress -IPAddress $ip -InterfaceIndex $adapterIndex … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (MSFT_NetIPAddress:ROOT/StandardCimv2/MSFT_NetIPAddress) [New-NetIPAddress], CimException + FullyQualifiedErrorId : Windows System Error 5010,New-NetIPAddress
The variables contain the correct, corresponding values.
Any idea why this happens, and any proper solutions? :-)
Thanks for reaching out about this error. This happens when DHCP is enabled on the interface. It automatically creates another IP address entry before you can create the new one. I updated the article with the command to disable DHCP on the interface.
Thanks for the quick reply! It seems to be working now, so thanks for the update. :-)
Leave a comment Cancel reply
![change static ip address powershell ' src=](https://itluke.online/wp-content/uploads/2019/02/cropped-itluke_cloud_icon-1.png?w=50)
- Already have a WordPress.com account? Log in now.
- Subscribe Subscribed
- Copy shortlink
- Report this content
- View post in Reader
- Manage subscriptions
- Collapse this bar
Tech Tips for Azure, OpenAI, & More NTWeekly.COM
Navigate the Cloud, Master the Code
How To Set a Static IP Address With PowerShell
In this blog post, I will show you how to assign and set a static IP address to a Windows 10 machine or Windows Server using PowerShell.
NetIPAddress
The NetIPAddress PowerShell module, which is included with PowerShell allows us to manage and configure the TCP\IP configuration of a Windows machine with PowerShell.
This option is very powerful because it allows us to programmatically set the IP address of a host using PowerShell, either remote or locally.
The PowerShell code \ script below will set the IP address of my machine with a static IP address, Default Gateway and a DNS server.
The code will assign the IP address to the network adapter and will exclude all virtual and VPN adapter.
![change static ip address powershell Back Home](https://www.alexandrumarin.com/wp-content/uploads/2015/08/amlogoalpha.png)
- Search Search Search …
Configuring Static IP and DNS Addresses with Windows PowerShell
Let’s dive into using Windows PowerShell to set static IP and DNS addresses on a server. In this walkthrough, I’ll walk you through the process with a concise breakdown of the steps.
Here’s the script, named `SetStaticIP.ps1`, that performs the IP and DNS configuration:
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter “ipenabled = ‘true'” $wmi.EnableStatic(“10.0.0.15”, “255.255.255.0”) $wmi.SetGateways(“10.0.0.1”, 1) $wmi.SetDNSServerSearchOrder(“10.0.0.100”)
![change static ip address powershell](https://www.alexandrumarin.com/wp-content/uploads/2023/08/powershell-ip-dns-300x278.png)
Even when dealing with script execution policy restrictions, Windows PowerShell ISE comes to the rescue. You can run the commands interactively within ISE, bypassing those policy limitations.
Breaking down the commands:
- $wmi = Get-WmiObject…: Retrieve network adapter configurations for adapters enabled for IP using the `Get-WmiObject` cmdlet and the `Win32_NetworkAdapterConfiguration` WMI class.
- $wmi.EnableStatic(…): Use the `EnableStatic` method to set the IP address and subnet mask.
- $wmi.SetGateways(…): Utilize `SetGateways` to specify gateway IP and metric.
- $wmi.SetDNSServerSearchOrder(…): Set the DNS server order using `SetDNSServerSearchOrder`.
Upon executing the commands, validate the IP change through GUI tools. These commands are efficient for resolving issues like race conditions, providing stability to your server environment.
In essence, Windows PowerShell showcases its flexibility and command-line prowess, even when dealing with policy constraints. It’s an invaluable tool for efficient IT management tasks, whether it’s IP configuration or tackling complex server challenges.
You may also like
![change static ip address powershell](https://www.alexandrumarin.com/wp-content/uploads/2024/04/blob.png)
Create Intune and Configuration Manager Lab in a few easy steps
Understanding the Lab Kit The Microsoft Intune and Microsoft Configuration Manager Evaluation Lab Kit serves as a powerful tool for IT professionals. […]
![change static ip address powershell](https://www.alexandrumarin.com/wp-content/uploads/2023/01/wmi-510x510.png)
Reset Windows device to OOBE state without user interaction
Recently I’ve ran into the situation where an SCCM (MECM) device needed to be migrated to Intune and the rule was that […]
![change static ip address powershell](https://www.alexandrumarin.com/wp-content/uploads/2023/07/tpmpowershell-510x510.png)
Identify the TPM version of your system
Have you ever wondered about the Trusted Platform Module (TPM) version on your computer? The TPM is a hardware-based security component that […]
![change static ip address powershell](https://www.alexandrumarin.com/wp-content/uploads/2023/09/IMG_5076.png)
WordPad Bids Adieu After 28 Years: Microsoft Pulls the Plug
Prepare to bid farewell to a long-standing companion as Microsoft brings the curtain down on WordPad. The technology giant recently revealed its […]
Leave a comment Cancel reply
Your email address will not be published. Required fields are marked *
Save my name, email, and website in this browser for the next time I comment.
Please enter an answer in digits: 7 + 18 =
How-To Geek
How to change your ip address using powershell.
We have already shown you how you can change your IP address from the command prompt, which required long netsh commands, now we are doing the same thing in PowerShell, without the complexity.
We have already shown you how you can change your IP address from the command prompt , which required long netsh commands, now we are doing the same thing in PowerShell, without the complexity.
Note: The following commands are new in PowerShell v3 and therefore require Windows 8, they also require an administrative command prompt.
Editors Note: This article is probably for our more geeky audience and requires some basic knowledge of IP Addressing and CIDR notation
Changing Your IP Address
We have seen people pulling out their hair trying to change their IP addresses using cryptic WMI classes in older versions of PowerShell, but that changed with PowerShell v3, there is now a NetTCPIP module that brings most of the functionality to native PowerShell. While a bit confusing at first, mostly due to the lack of documentation at the moment, it starts to make sense once the geeks shows you how its done.
Changing an IP Address can be done using the New-NetIPAddress cmdlet, it has a lot of parameters, some of which, are not even documented in Get-Help. So here it is:
New-NetIPAddress --InterfaceAlias "Wired Ethernet Connection" --IPv4Address "192.168.0.1" --PrefixLength 24 -DefaultGateway 192.168.0.254
This assumes the following:
- The name of the interface you want to change the IP address for is Wired Ethernet Connection
- You want to statically assign an IP address of 192.168.0.1
- You want to set a subnet mask of 255.255.255.0 (which is /24 in CIDR notation)
- You want to set a default gateway of 192.168.0.254
You would obviously switch the settings out for some that match the addressing criteria for your network.
Setting Your DNS Information
Now here comes another tricky part, it turns out that there is a whole separate module called DNSClient that you have to use to manipulate your DNS Settings. To change your DNS Server you would use:
Set-DnsClientServerAddress -InterfaceAlias "Wired Ethernet Connection" -ServerAddresses 192.168.0.1, 192.168.0.2
This assumes that you want to set the primary DNS server for Wired Ethernet Connection to 192.168.0.1 and the secondary DNS server to 192.168.0.2. That's all there is to it.
![change static ip address powershell The Back Room Tech logo](https://s11921.pcdn.co/wp-content/themes/tbrt/images/header-logo.png)
Configure Static IP Address on a Network Adapter using PowerShell
In this tutorial, I am going to show you how to configure a static IP address on a system that has one network card through PowerShell. This can come in handy when we have many servers that we are deploying and we would like to automate the IP addressing based on an Excel spreadsheet, for example, or if we are deploying using VMware customization templates.
This specific example will show you the exact commands needed to accomplish this. It is a basic tutorial and I do not include any steps on connecting to Excel through COM objects or anything of the sort.
If you want to do the same thing using the normal command prompt, read my previous post on setting a static IP address using the command prompt . Finally, you can also set a static IP address via Network and Sharing Center .
Configure Static IP using PowerShell
So let us dive right in. To start, make sure you open an administrator PowerShell window, otherwise you will get an Access is Denied error when trying to run the command below.
We will be using two PowerShell commands, New-NetIPAddress and Set-DNSClientServerAddress .
On the server that we want to configure, we open PowerShell and type the below command:
Here is an example below:
![change static ip address powershell Configure Static IP Address on a Network Adapter using PowerShell image 1](https://s11921.pcdn.co/wp-content/uploads/powershell-new-netipaddress.png)
All the arguments are self-explanatory, apart from the InterfaceIndex one. Over here instead of putting in the numerical value of the Interface Index, I just ran the Get-NetAdapter command inside my current command with filtering to output only the integer value of the Interface Index.
If you have multiple network adapters on your system, you can remove the function and simply enter the numerical value corresponding to the desired interface.
If the command completes successfully, we should get the result as shown below:
![change static ip address powershell Configure Static IP Address on a Network Adapter using PowerShell image 2](https://s11921.pcdn.co/wp-content/uploads/powershell-static-ip-address.png)
Now we have our IP Address, Subnet Mask and Default Gateway configured. However, one thing is missing. These are the DNS Server addresses.
To configure the DNS Server addresses, we run the following command:
IP1 is the primary DNS Server, IP2 is the secondary and all the others are the third and so forth.
Here is an example:
![change static ip address powershell Configure Static IP Address on a Network Adapter using PowerShell image 3](https://s11921.pcdn.co/wp-content/uploads/powershell-set-dns-server.png)
That is it. Very simple and quick way to change IP settings for a network adapter using PowerShell. Any questions or comments are welcome! Enjoy!
Sabrin Freedman-Alexander has been a Systems Administrator for over 12 years. He's currently the Principal Systems Administrator at one of the biggest Healthcare Campuses in Israel. He is a expert in Highly Available solutions and has numerous technical certifications. Read Sabrin's Full Bio
Read More Posts:
![change static ip address powershell](https://s11921.pcdn.co/wp-content/uploads/driver-signing-140x85.png)
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
![change static ip address powershell WinTips.org](https://www.wintips.org/wp-content/uploads/2021/05/Win-Tips5g1.png)
How to Set Static IP Address on Windows 11/10.
A static IP address is a dedicated, permanent IP address that is manually assigned to a device by a user. Unlike dynamic IP addresses, which are assigned by a DHCP Server and can change over time, static IP addresses remain fixed and do not change over time.
A static IP address can be useful in many situations, such as when hosting a website or server, setting up a virtual private network (VPN) server, forwarding ports to a specific device, accessing a networked printer, and more.
Whatever your reason may be, assigning a static IP address is a simple and straightforward task that can be done directly on the device. In this article, we will cover various methods for setting up a static IP address on Windows 11/10.
How to Assign a Static IP Address on a Windows 11 PC.
- Set Static IP on Windows 11 Settings.
- Set Up Static IP Address in Network Connections.
- Assign a Static IP Address through Command Prompt.
- Specify a Static IP Address with PowerShell.
Method 1: Manually Set a Static IP Address using Windows Settings
The most straightforward method for setting a static IP address is through Windows Settings.
1. Press Windows + I keys to open the Windows Settings app
2. Select the Network & internet tab in the left pane and then click on the active/connected network connection ( Ethernet or WiFi ) on the right pane.
![network settings How to Set Static IP Address on Windows 11/10.](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-98.png)
3. On the network configuration page:
a. Note the current IPv4 address and the IPv4 DNS server address which automatically assigned by DHCP (usually your router).
b. Click the the Edit button next to the IP assignment section to set a Static IP Address.
![IP assignment How to Assign Static IP Address on Windows 11/10.](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-99.png)
4. In Edit IP settings , change the setting from Automatic (DHCP) to Manual using the drop-down menu.
![clip_image006 clip_image006](https://www.wintips.org/wp-content/uploads/2023/07/clip_image006_thumb.png)
5. Then, Turn On the IPv4 toggle and fill out the fields below as follows:
- IP address: Enter the static IP Address that you want to use. *
* Note: if you want to set the assigned DHCP IPv4 address you noted before as static, type this address here. (e.g. "192.168.1.217" in this example)
- Subnet mask: Type 255.255.255.0
- Gateway: Enter the IP address of your router. [Usually, this is the same as the IPv4 DNS server address you noted before. (e.g. "192.168.1.1" in this example)]
- Preferred DNS: Type the IPv4 DNS server address you noted before. (e.g. "192.168.1.1" in this example).
6. When finish, click Save and you done. You have successfully changed the IP address from dynamic to static. *
* Note: If, after following the instructions above, you lose your network connectivity, make sure you have set the correct IP address, Subnet Mask, Gateway and DNS, or change to Automatic (DHCP) again.
![ipv4 Assign Static IPv4 Address on Windows 10/11](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-100.png)
Method 2: Assign a Static IP Address in Network Connections settings.
The classic and my favorite method to change the IP Address in Windows, is through the Network Connections applet.
![image image](https://www.wintips.org/wp-content/uploads/2016/06/image_thumb-28.png)
3a. In Network Connections window, double-click on the active Network Connection/Adapter and click Details.
![Network Connection Details Network Connection Details](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-29.png)
3b. In Network Connection Details window, notice and write down the following information:
- IPv4 Address (e.g. "192.168.1.101")
- IPv4 Subnet Mask (e.g. "255.255.255.0")
- IPv4 Default Gateway (e.g. "192.168.1.1")
- IPv4 DNS Server (e.g. "192.168.1.1")
![IP4 Address Settings IPv4 Address Settings](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-30.png)
3c. When done, click the Close button.
4. Now, in Network Status window, click Properties.
![Network Connection Properties Network Connection Properties](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-31.png)
5. Select Internet Protocol Version 4 (TCP/IPv4) and click Properties again.
![IPv4 TCPI-IP Properties IPv4 TCPI/IP Properties](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-32.png)
6. In ' Internet Protocol Version 4 (TCP/IPv4) Properties' window, do the following:
a. Check the Use the following IP address option and fill the below fields as follows:
b. At IPv4 Address field, type the static IP Address that you want to use, or if you want to set the assigned DHCP IPv4 address you noted before as static, type this address. (e.g. "192.168.1.101" in this example)
c. Then press the Tab button once to fill automatically the Subnet mask field, or type manually the Subnet mask "numbers" you noted in the step-3b above (e.g. 255.255.255.0").
d. At Default gateway field, type the IP Address of the "IPv4 Default Gateway" you noted before (This is the IP Address of your router. e.g. "192.168.1.1" in this example)
![Set Static IP Address Set Static IP Address](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-33.png)
e. Next, check the Use the following DNS addresses option and type below the IPv4 DNS Server address you noted before (e.g. "192.168.1.1" in this example), or type your preferred DNS server's address, such as the Google's public DNS Server's addresses " 8.8.8.8 " for Preferred DNS and " 8.8.4.4 " for Alternate DNS, as in this example.
![Set DNS Address Set Preferred DNS Server Address](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-34.png)
7. Now, check the Validate settings upon exit option and click OK to save the changes.
![ip settings set static ip address on windows](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-35.png)
8. Finally, click Close to close the adapter’s properties window and you done! *
* Note: If, after following the instructions above, you lose your network connectivity, make sure you have set the correct IP address, Subnet Mask, Gateway and DNS, or change back to the Dynamic IP assignment, by checking both the " Obtain an IP address automatically " & " Obtain DNS Server addresses automatically " options in the above screen.
![Static IP Address Set Static IP Address on Windows 11/10](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-36.png)
Method 3: Set Up a Static IP Address using Command Prompt
If you like commands, then here are the instructions to change your Dynamic IP address to Static, via command line.
1. Open Windows Search, type command prompt, and select Run as administrator . Then, click Yes on the UAC prompt to proceed.
![command prompt command prompt](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-101.jpg)
2. Proceed and view your current IP Address configuration by giving the below command and pressing Enter :
- ipconfig/all
![ipconfig ipconfig/all](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-101.png)
3. After command execution, scroll up and and note the name of the network adapter that you are currently using (e.g. "Wi-Fi" in this example), and then note the following details below it:
- IPv4 Address (e.g. "192.168.1.100")
- Subnet Mask (e.g. "255.255.255.0")
- Default Gateway (e.g. "192.168.1.1")
- DNS Server (e.g. "192.168.1.1")
![ip configuration ip configuration](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-102.jpg)
2a. To change the Dynamic IP address configuration you already have to a static IP address configuration, enter the following command:*
- netsh interface ip set address name=" Adapter's_Name " static IPAddress SubnetMask DefaultGateway
* Note: In the above command:*
- Replace Adapter's_Name with the name of the active network adapter, (e.g. " Wi-Fi " in this example)
- Replace the IPAddress with the IPv4 Address you noted above (e.g. " 192.168.1.100 " in this example), or type the Static IP Address that you want to use.
- Replace the SubnetMask with the " Subnet mask" address you noted above (e.g. " 192.168.1.1 " in this example).
* In this example, the command will be:
- netsh interface ip set address name="Wi-Fi" static 192.168.1.100 255.255.255.0 192.168.1.1
![set static ip addess command setup static ip address command prompt](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-102.png)
2b. To assign a DNS server address, type or paste the following command and press Enter :*
- netsh interface ip set dns name=" Adapter's_Name " static DnsServer
- Replace the DnsServer with the DNS Server's IP Address of the DNS you noted above (e.g. " 192.168.1.1 " in this example), or the type the IP address of the DNS Server that you want to use. **
** e.g. In this example will want to use Google's Public DNS server (8.8.8.8). So , the command will be:
- netsh interface ip set dns name="Wi-Fi" static 8.8.8.8
![set dns address set dns address command](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-103.png)
2c. If you want to assign an alternate DNS server address, (e.g. "8.8.4.4"), give the following command and press Enter : *
- netsh interface ip add dns name=" Wi-Fi " 8.8.4.4 index=2
* Note: Replace Wi-Fi with your adapter's name and change 8.8.4.4 with your desired alternative DNS server address.
![set alternate dns address set alternate dns address](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-104.png)
3. When finish, close the command prompt window and you're done!
Method 4: Set a Static IP Address using PowerShell.
Another way to change to a Static IP address on your device, is via PowerShell.
1. Press the Windows key, type powershell in the search bar, and click Run as Administrator to open Windows PowerShell as administrator .
![powershell powershell](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-105.jpg)
2. Now give the following PowerShell command and hit Enter to view the current Network IP configuration:
- Get-NetIPConfiguration
![Get-NetIPConfiguration view network ip configuration](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-105.png)
3. Now note the InterfaceIndex of the active network adapter (e.g. "22" in this example), and the following details below it:
- IPv4Address (e.g. "192.168.1.100")
- IPv4Default Gateway (e.g. "192.168.1.1")
![set ip address powershel assign ip address powershel](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-106.png)
4. Run the following command to set up a static IP address: *
- New-NetIPAddress -InterfaceIndex Number -IPAddress New- IPv4Address -PrefixLength 24 -DefaultGateway IPv4DefaultGateway
* Notes 1. In the above command:
- Replace Number with the Interface's Index number you noted above (e.g. "22" in this example)
- Replace New- IPv4Address with the static IP Address you want to use. (e.g. "192.168.1.150" in this example), or type the IPv4Address you noted before.
- Replace IPv4DefaultGateway with the IP Address you noted above (e.g. "192.168.1.1" in this example.
e.g. To set the IPv4 Address to "192.168.1.150", type:
New-NetIPAddress -InterfaceIndex 22 -IPAddress 192.168.1.150 -PrefixLength 24 -DefaultGateway 192.168.1.1
2. The number "24" is usually the default prefix (Subnet Mask) for home networks.
![set dns address powershel set dns address powershel](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-107.png)
5. To add a primary DNS server to your network adapter, run the below command:*
- Set-DnsClientServerAddress -InterfaceIndex Number -ServerAddresses DnsServer
Note: In the above command:
- Replace DnsServer with the IP of the DNS Server you noted above (e.g. "192.168.1.1" in this example), or type the IP Address of your referred DNS Server.
Example No1: To use the current DNS server's IP address in this example:
- Set-DnsClientServerAddress -InterfaceIndex 22 -ServerAddresses 192.168.1.1
Example No2: To set another DNS Server with IP address "208.67.222.222" type:
- Set-DnsClientServerAddress -InterfaceIndex 22 -ServerAddresses 208.67.222.222
![powershell set alternate dns address powershel](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-108.png)
Example No3: To specify both a Preferred and an Alternate DNS Server with IP's 208.67.222.222 & 208.67.220.220 respectively, give the following command:
- Set-DnsClientServerAddress -InterfaceIndex 22 -ServerAddresses 208.67.222.222, 208.67.220.220
![image image](https://www.wintips.org/wp-content/uploads/2023/07/image_thumb-109.png)
That's it! Which method worked for you? Let me know if this guide has helped you by leaving your comment about your experience. Please like and share this guide to help others.
We're hiring
We're looking for part-time or full-time technical writers to join our team! It's about a remote position that qualified tech writers from anywhere in the world can apply. Click here for more details.
- Recent Posts
- FIX: Windows 11 File Explorer Address and Menu bars are missing after KB5036980 Update. - May 15, 2024
- FIX: Facebook Marketplace opens automatically when you open the Facebook app on Mobile devices. - May 13, 2024
- Fix: 0x80070426 in Xbox app, Microsoft Store or in Windows Update. - May 1, 2024
Konstantinos Tsoukalas
Related posts.
![FIX: Windows 11 File Explorer Address and Menu bars are missing after KB5036980 Update. FIX: Windows 11 File Explorer Address and Menu bars are missing after KB5036980 Update.](https://www.wintips.org/wp-content/uploads/2024/05/image_thumb-22-150x150.png)
How to , Tutotial , Windows , Windows 11
FIX: Windows 11 File Explorer Address and Menu bars are missing after KB5036980 Update.
![FIX: Facebook Marketplace opens automatically when you open the Facebook app on Mobile devices. FIX: Facebook Marketplace opens automatically when you open the Facebook app on Mobile devices.](https://www.wintips.org/wp-content/uploads/2024/05/image_thumb-30-150x150.png)
How to , Tutotial
FIX: Facebook Marketplace opens automatically when you open the Facebook app on Mobile devices.
![Fix: 0x80070426 in Xbox app, Microsoft Store or in Windows Update. Fix: 0x80070426 in Xbox app, Microsoft Store or in Windows Update.](https://www.wintips.org/wp-content/uploads/2024/04/image_thumb-43-150x150.png)
How to , Tutotial , Windows , Windows 10 , Windows 11
![](http://paperhelp.pw/777/templates/cheerup2/res/banner1.gif)
Fix: 0x80070426 in Xbox app, Microsoft Store or in Windows Update.
Leave a reply cancel reply.
Your email address will not be published. Required fields are marked *
How to change from static to dynamic IP address on Windows 10
Are you using a static IP address? Here are four ways to switch to a dynamic configuration on Windows 10.
On Windows 10, you can configure a network adapter to use a static IP address manually, or you can use an automatically assigned configuration using the local Dynamic Host Configuration Protocol (DHCP) server.
Although using a static IP address is recommended for devices that provide services to network users, as its configuration never changes, it may come a time when you may no longer need this configuration, and a dynamically assigned network configuration will be more suited.
If you use a static IP address and need to switch to a dynamic configuration, it’s possible to perform this task in several ways, including using the Settings app, Control Panel, Command Prompt, and even PowerShell.
In this guide , you’ll learn the steps to remove a static IP address configuration to obtain a dynamic configuration from the DHCP server on Windows 10 .
Change to dynamic IP address (DHCP) from Settings
Change to dynamic ip address (dhcp) from command prompt, change to dynamic ip address (dhcp) from powershell, change to dynamic ip address (dhcp) from control panel.
To enable DHCP to obtain a TCP/IP configuration automatically on Windows 10, use these steps:
Open Settings on Windows 10.
Click on Network & Internet .
Click on Ethernet or Wi-Fi .
Click the network connection.
Under the “IP settings” section, click the Edit button.
![change static ip address powershell Edit IP settings on Windows 10](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/edit-ip-settings-app-windows10-2022.webp?resize=777%2C387&quality=78&strip=all&ssl=1)
Use the Edit IP settings drop-down menu and select the Automatic (DHCP) option.
![change static ip address powershell Enable automatic (DHCP) IP address using Settings app](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/enable-dhcp-ip-address-settings-2022.webp?resize=777%2C387&quality=78&strip=all&ssl=1)
Click the Save button.
Once you complete the steps, the networking stack configuration will reset, and your device will request an IP address from the DHCP server (usually your router).
To switch from a static TCP/IP configuration to a dynamically assigned configuration using DHCP with Command Prompt, use these steps:
Open Start .
Search for Command Prompt , right-click the top result, and select the Run as administrator option.
Type the following command to note the name of the network adapter and press Enter
![change static ip address powershell Network adapter name using Command Prompt](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/ipconfig-cmd-win10.webp?resize=827%2C506&quality=78&strip=all&ssl=1)
Type the following command to configure the network adapter to obtain its TCP/IP configuration using DHCP and press Enter :
In the command, make sure to change “Ethernet1” for the adapter’s name that you want to configure.
![change static ip address powershell Enable DHCP on Windows 10 using Command Prompt](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/enable-dhcp-windows-10-cmd-2022.webp?resize=827%2C287&quality=78&strip=all&ssl=1)
After completing the steps, the network adapter will stop using a static IP address, and it’ll obtain a configuration automatically from the DHCP server.
To remove a static IP and DNS addresses to use a dynamic configuration using PowerShell, use these steps:
Search for PowerShell , right-click the top result, and select the Run as administrator option.
Type the following command to note the “InterfaceIndex” number for the network adapter and press Enter :
![change static ip address powershell Network interface information using PowerShell](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/powershell-interfaceindex-number-command.webp?resize=827%2C396&quality=78&strip=all&ssl=1)
Type the following command to enable the network adapter to obtain its TCP/IP configuration using DHCP and press Enter :
In the command, make sure to change “Ethernet0” for the adapter’s name that you want to configure.
Type the following command to enable the network adapter to obtain its DNS configuration using DHCP and press Enter :
In the command, change “3” for the InterfaceIndex for the adapter to configure.
![change static ip address powershell Enable DHCP for dynamic IP assignment using PowerShell](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/enable-dhcp-dynamic-ip-powershell-windows-10.webp?resize=827%2C157&quality=78&strip=all&ssl=1)
Once you complete the steps, the IP and DNS addresses will be reset from the adapter, and your computer will receive a new dynamic configuration from DHCP.
To configure a network adapter to use a dynamic IP address using Control Panel, use these steps:
Open Control Panel .
Click on Network and Internet .
Click on Network and Sharing Center .
On the left pane, click the “Change adapter settings” option.
![change static ip address powershell Network and Sharing Center in Control Panel](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/network-sharing-center-cp-2022.webp?resize=827%2C424&quality=78&strip=all&ssl=1)
Right-click the network adapter and select the Properties option.
Select the “Internet Protocol Version 4 (TCP/IPv4)” option.
Click the Properties button.
![change static ip address powershell Ethernet1 Properties on Windows 10](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/ethernet1-properties-controlpanel.webp?resize=363%2C468&quality=78&strip=all&ssl=1)
Select the “Obtain an IP address automatically” option.
Select the “Obtain the following DNS server address automatically” option.
![change static ip address powershell Enable dynamic IP address (DHCP) using Control Panel](https://i0.wp.com/pureinfotech.com/wp-content/uploads/2019/02/enable-dhcp-dynamic-ip-control-panel-2022.webp?resize=400%2C455&quality=78&strip=all&ssl=1)
Click the OK button.
After completing the steps, the statically assigned TCP/IP configuration will no longer be available, and the computer will automatically request a dynamic network configuration from the network.
Mauro Huculak is a Windows How-To Expert who started Pureinfotech in 2010 as an independent online publication. He has also been a Windows Central contributor for nearly a decade. Mauro has over 14 years of experience writing comprehensive guides and creating professional videos about Windows and software, including Android and Linux. Before becoming a technology writer, he was an IT administrator for seven years. In total, Mauro has over 20 years of combined experience in technology. Throughout his career, he achieved different professional certifications from Microsoft (MSCA), Cisco (CCNP), VMware (VCP), and CompTIA (A+ and Network+), and he has been recognized as a Microsoft MVP for many years. You can follow him on X (Twitter) , YouTube , LinkedIn and About.me . Email him at [email protected] .
- Windows Subsystem for Android gets January 2023 update
- How to access Advanced startup (WinRE) on Windows 10
We hate spam as much as you! Unsubscribe any time Powered by follow.it ( Privacy ), our Privacy .
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Set-Dns Client Server Address
Sets DNS server addresses associated with the TCP/IP properties on an interface.
Description
The Set-DnsClientServerAddress cmdlet sets one or more IP addresses for DNS servers associated with an interface. This cmdlet statically adds DNS server addresses to the interface. If this cmdlet is used to add DNS servers to the interface, then the DNS servers will override any DHCP configuration for that interface.
Example 1: Set the DNS server addresses on an interface with a specified index value
This example sets the DNS server addresses on a specified interface with the index value of 12.
Example 2: Reset a DNS client to use the default DNS server addresses
This example resets the DNS client to use the default DNS server addresses specified by DHCP on the interface with an index value of 12.
Runs the cmdlet as a background job. Use this parameter to run commands that take a long time to complete.
The cmdlet immediately returns an object that represents the job and then displays the command prompt. You can continue to work in the session while the job completes. To manage the job, use the *-Job cmdlets. To get the job results, use the Receive-Job cmdlet.
For more information about Windows PowerShell background jobs, see about_Jobs .
-CimSession
Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.
Prompts you for confirmation before running the cmdlet.
-InputObject
Specifies the input to this cmdlet. You can use this parameter, or you can pipe the input to this cmdlet.
-InterfaceAlias
Specifies the friendly name of the interface.
-InterfaceIndex
Specifies the index number of the interface.
Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.
-ResetServerAddresses
Resets the DNS server IP addresses to the default value.
-ServerAddresses
Specifies a list of DNS server IP addresses to set for the interface.
-ThrottleLimit
Specifies the maximum number of concurrent operations that can be established to run the cmdlet. If this parameter is omitted or a value of 0 is entered, then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit applies only to the current cmdlet, not to the session or to the computer.
Validates that one or more IP addresses are responsive DNS servers before the IP addresses are set to the interface. This parameter must be used with the ServerAddress parameter.
Shows what would happen if the cmdlet runs. The cmdlet is not run.
CimInstance
The Microsoft.Management.Infrastructure.CimInstance object is a wrapper class that displays Windows Management Instrumentation (WMI) objects. The path after the pound sign ( # ) provides the namespace and class name for the underlying WMI object.
The MSFT_DNSClientServerAddress class has the various DNS server IP addresses configured on a given interface. If no interface is specified, then all interfaces are configured.
Related Links
- Get-DnsClientServerAddress
Was this page helpful?
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see: https://aka.ms/ContentUserFeedback .
Submit and view feedback for
Additional resources
- Skip to primary navigation
- Skip to main content
- Skip to primary sidebar
![change static ip address powershell Think PowerShell](https://thinkpowershell.com/wp-content/uploads/thinkpowershell-wordpress-header-monochrome.png)
Think PowerShell
PowerShell for IT Pros
Change DNS Servers for Computers with Static IP Addresses
Aaron Rothstein · March 27, 2017 · 8 Comments
![change static ip address powershell DNS Server Settings Screenshot](https://thinkpowershell.com/wp-content/uploads/532-DNS-Server-Settings-Screenshot.png)
Easily change DNS servers for computers with static IP addresses using PowerShell. Run locally or remote.
Changing DNS servers
Recently I provisioned new domain controllers as part of a migration from a 2008 R2 Active Directory forest to a 2016 Active Directory forest. Like the existing 2008 R2 domain controllers, the new domain controllers are configured as AD integrated DNS servers and will be the primary and secondary DNS servers used on the internal network.
Changing DNS servers for clients using DHCP is a trivial matter; just update Option 6 for the DHCP scope with the new name server IP addresses and restart the client (or wait until they renew their lease).
However if you are like a lot of environments, you have Windows servers and maybe even workstations configured with static IP addresses and static DNS servers. How can you systematically update these configurations?
Change DNS servers with Win32_NetworkAdapterConfiguration
We can use PowerShell and Get-WmiInstance or Get-CimInstance (Win 8/2012 or later). For compatibility, we will be demonstrating using Get-WmiInstance .
In our scenario, our old DNS servers were 192.168.1.11 and 192.168.1.12. We will be replacing these with 192.168.1.13 and 192.168.1.14. We use the following snippet leveraging the class Win32_NetworkAdapterConfiguration to return a list of all non-DHCP adapters with DNS servers configured.
To see the current DNS servers, we run the following:
To update the DNS servers for adapters meeting this criteria, we run the following:
To confirm the servers have been updated, re-run our original Get sequence:
Remotely updating DNS servers for set of computers
The previous section covered the basic updating of the DNS servers locally on a single computer. However you may have the need to update multiple computers remotely.
One approach would be to query your Active Directory to get a list of all computers that have statically assigned IP addresses. For example, it may be that all of your computers running a Windows Server OS have static IPs.
Get all “Windows Server” AD computers
We can get all of the the computers in Active Directory that are running a “Windows Server” build using the following Get-ADComputer query:
Use Invoke-Command to update DNS on remote computers
We now have a set of computers to process. We will use Invoke-Command to connect via WinRM to the remote computer and execute the previous commands locally on the computer.
Why we used Invoke-Command
We could use the WMI cmdlets directly against the remote computer, but it would require all of the necessary network port access and permissions for using WMI remotely. Connecting using WinRM only requires a single network port to be opened and lets us run all other cmdlets without having to give a lot of thought to remote security and performance over the network.
Set-DnsClientServerAddress: Windows 8/2012 or newer
The method described above is intended for maximum compatibility: it will work with Windows Server 2003 all the way through Windows Server 2016. If however your environment is running Windows 8 / Windows Server 2012 and above, you do not need to use the WMI cmdlets, you can use the newer cmdlet Set-DnsClientServerAddress .
Note that we specified the InterfaceIndex . Other interface identification options are InterfaceAlias or you can pass a CimInstance for an interface to the cmdlet. You could use this cmdlet in hybrid with our previous Get-WmiObject query:
Using this approach as a starting point, you can modify as required fit your own environment’s requirements to confidently and efficiently update DNS servers for computers with statically assigned IPs.
Reader Interactions
March 27, 2017 at 7:42 pm
For big companies this is likely to fail on older computers — and they are still likely to be around.
Fall back to NetSh, it’s on almost everything and PowerShell can drive it easily enough.
March 28, 2017 at 7:37 am
This method will work for Windows XP / 2003 computers if they have WMF installed and configured. You are right though, anything older than that and you will have to resort to legacy tool sets.
December 24, 2019 at 11:20 am
I am new to PowerShell and Windows DC’s but I need help simply changing the DC static IP to another Static IP. It seems you are using DHCP here and I don’t think that will work. In my use-case I am moving a DC from one environment to another. I need to be able to apply the changes remotely. Using Infrastructure as code (IaC) e.g. aws CloudFormation.
March 7, 2020 at 2:12 pm
Hey Mike, I’m guessing you have already addressed your issue, but for changing the IP address of a host (DC or otherwise), you would use the cmdlet Set-NetIPAddress ( https://docs.microsoft.com/en-us/powershell/module/nettcpip/set-netipaddress?view=win10-ps ).
For a domain controller, here are additional recommended steps from a TechNet article that is no longer available: “After you change the IP address of a domain controller, you should run the ipconfig /registerdns command to register the host record and dcdiag /fix command to ensure that service records are appropriately registered with DNS”
June 11, 2020 at 4:13 pm
Good afternoon,
I have been trying to turn part of this into a script that I can setup in Group Policy and push out network wide, but I am having trouble.
The part I am using is: $NewDnsServerSearchOrder = “192.168.1.13”,”192.168.1.14″
$Adapters | ForEach-Object {$_.SetDNSServerSearchOrder($NewDnsServerSearchOrder)} | Out-Null
Whenever I try to run it in PS ISE I get the following error: “You cannot call a method on a null-valued expression”
I am not sure what I am doing wrong here because it runs perfectly fine in a PS window. Any Suggestions?
June 13, 2020 at 9:28 am
Hi Greg, Replying here as well, we can continue the conversation either on Facebook or here, whichever you prefer.
It appears $Adapters is null. Can you confirm nothing is being returned when running the following in the ISE: Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne ‘True’ -and $_.DNSServerSearchOrder -ne $null}
October 7, 2020 at 3:09 pm
I am not a PS expert – How would the above scripts work on servers that have multiple NICs in various VLANs if I only want to change DNS on a specific NIC? And are there arguments to provide credentials if I am remotely acting on servers requiring different administrative credentials for making these modifications?
December 20, 2020 at 12:26 am
You would want to look at doing some additional filtering during the initial querying, under the ‘Where-Object’ call. For example, you could query by adapter name or other properties: $Adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DHCPEnabled -ne ‘True’ -and $_.DNSServerSearchOrder -ne $null}
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
- About the Authors
How to Change IP address of Domain Controller (DC)
Changing IP addresses on a corporate network may require to change IP address of domain controller (one or more). Responsible for authentication, authorization, DNS resolution on Windows networks, domain controllers are a critical part of the network infrastructure. Therefore, a change of IP address on a domain controller must be properly planned to avoid network problems.
Important! Changing the IP address of a domain controller is not a usual management task. Therefore, it is recommended to simply promote a new DC with a new IP address in the target subnet. The old DC should then be downgraded to a member server. This minimizes the risk of breaking anything on your network.
Preparing for Domain Controller IP Address Change
There are a few preparatory steps you need to take before changing the static IP address of a DC:
- Make sure there are at least two AD domain controllers online on your network.
- Perform AD and replication health checks and fix any issues found.
![change IP address of domain controller change IP address of domain controller](https://theitbros.com/wp-content/uploads/2024/05/word-image-38300-1.png)
- In the Active Directory Sites and Services console ( dssite.msc ), check that the new domain controller IP address has an IP subnet associated with the AD site. Create an IP subnet if required.
How to Change IP Address of Domain Controller?
In this example, we are going to change the old static IP address of the domain controller 192.168.1.10 to a new one 192.168.158.10 .
- Connect to the domain controller host console. Depending on your infrastructure, this can be a VM console, iLO, iDRAC, IPMI remote console, etc. Do not use RDP to access the DC as the connection will be lost if the IP is changed.
- Open the Network Connection Control Panel by running the command ncpa.cpl
![change domain controller ip change domain controller ip](https://theitbros.com/wp-content/uploads/2024/05/word-image-38300-2.png)
- Click OK > OK to save changes.
Now you need to register the new domain controller IP address in DNS. Open a command prompt as an administrator and run the commands:
To force an update of all the resource records of the domain controller in the DNS (_msdcs, _sites, _tcp, _udp, etc.), run:
![change ip address on domain controller change ip address on domain controller](https://theitbros.com/wp-content/uploads/2024/05/word-image-38300-3.png)
Check the health of the domain controller and replication after 20-30 minutes:
![change ip active directory domain controller change ip active directory domain controller](https://theitbros.com/wp-content/uploads/2024/05/word-image-38300-4.png)
Re-check the Domain Controller health:
Updating Domain Controller IP Adress on Clients
Once you have changed the IP address of the domain controller, you will need to update it on all the clients that have been using it. These could be other DCs, computers, network devices (printers, scanners, MFPs, etc).
![domain controller change ip address domain controller change ip address](https://theitbros.com/wp-content/uploads/2024/05/word-image-38300-5.png)
- If you are assigning IP settings to client devices via DHCP, specify a new DNS address in the DHCP scope settings. In order for DHCP clients to receive new IP settings, you must reboot them or run the commands: ipconfig /renew ipconfig /flushdns
- Manually change DNS settings for devices with static IP settings.
Make sure your network clients are able to authenticate on the domain controller with the new IP address.
Our newsletter is full of great content!
Subscribe TheITBros.com newsletter to get the latest content via email.
![change static ip address powershell kardashevsky cyril](https://theitbros.com/wp-content/uploads/2020/07/cropped-kardashevskycyril-100x100.png)
Cyril Kardashevsky
I enjoy technology and developing websites. Since 2012 I'm running a few of my own websites, and share useful content on gadgets, PC administration and website promotion.
Configuring Active Directory Sites and Subnets
Leave a comment cancel reply.
Save my name, email, and website in this browser for the next time I comment.
This site uses Akismet to reduce spam. Learn how your comment data is processed .
![](http://paperhelp.pw/777/templates/cheerup2/res/banner1.gif)
IMAGES
VIDEO
COMMENTS
The Set-NetIPAddress cmdlet modifies IP address configuration properties of an existing IP address. To create an IPv4 address or IPv6 address, use the New-NetIPAddress cmdlet. ... then Windows PowerShell® calculates an optimum throttle limit for the cmdlet based on the number of CIM cmdlets that are running on the computer. The throttle limit ...
From the properties, you can note down the interface index value. then you can use the below command to set the IP address. If you are setting the IP address first time the use command as. New-NetIPAddress -IPAddress 192.168.10.100 -PrefixLength 24 -DefaultGateway 192.168.10.1 -InterfaceIndex 4.
In PowerShell, you can manage network adapter settings to disable or enable static (manually assigned) and DHCP (automatically assigned) IP addresses using the Set-NetIPInterface cmdlet. The specific command depends on whether you want to disable static or DHCP addresses. Here are the PowerShell commands for each scenario:
PowerShell: Change Adapter from Static IP Address to DHCP. To configure your computer to obtain a dynamic IP address for the network adapter from the DHCP server, run this command: Set-NetIPInterface -InterfaceAlias Ethernet0 -Dhcp Enabled. Clear the DNS server settings: Set-DnsClientServerAddress -InterfaceAlias Ethernet0 -ResetServerAddresses
New-NetIPAddress : The object already exists. Remove this IP address from the persistent store. Remove-NetIPAddress -IPAddress '192.168.100.156'. Create a new IP address entry. New-NetIPAddress -InterfaceIndex 12 -AddressFamily IPv4 -IPAddress '192.168..50' -PrefixLength 24. If the gateway is different from the former one, remove it, and set a ...
Set static IP address. You may want to set a static IP if your computer is a server or need to set static IPs in an environment without DHCP. You can do this using the New-NetIPAddress cmdlet. This is equivalent to opening the Properties of a network connection and manually configuring the adapter. PS C:\Windows\system32> New-NetIPAddress ...
The PowerShell code \ script below will set the IP address of my machine with a static IP address, Default Gateway and a DNS server. The code will assign the IP address to the network adapter and will exclude all virtual and VPN adapter.
Let's dive into using Windows PowerShell to set static IP and DNS addresses on a server. In this walkthrough, I'll walk you through the process with a concise breakdown of the steps. ... Upon executing the commands, validate the IP change through GUI tools. These commands are efficient for resolving issues like race conditions, providing ...
Tutorial Powershell - Configure a static IP address [ Step by step ] Learn how to use Powershell to configure a static IP address on the network adapter of a computer running Windows in 5 minutes or less.
With the cmdlets you have learned so far, it is time to put your new knowledge to work. For this tutorial, you will assign a static IP address, gateway, and DNS servers to a Windows Server 2022 host. The commands from this point forward only change the IP address, gateway, and DNS settings for the specified network adapter.
Setting a static IP address from DHCP. When going from DHCP to static, the PowerShell cmdlets treat this as a "new" IP address, thus the use of the New-NetIpAddresscmdlet. To use this, you'll need to reference the current IP address and pipe it to New-NetIpAddress using the expected IP address, subnet mask prefix length, and default gateway.
So here it is: New-NetIPAddress --InterfaceAlias "Wired Ethernet Connection" --IPv4Address "192.168..1" --PrefixLength 24 -DefaultGateway 192.168..254. This assumes the following: The name of the interface you want to change the IP address for is Wired Ethernet Connection. You want to statically assign an IP address of 192.168..1.
We will be using two PowerShell commands, New-NetIPAddress and Set-DNSClientServerAddress. On the server that we want to configure, we open PowerShell and type the below command: New-NetIPAddress -IPAddress <ip_address> -DefaultGateway <default_gateway> -PrefixLength <subnet_mask_in_bit_format> -InterfaceIndex (Get-NetAdapter).InterfaceIndex.
To set a static IP address with PowerShell, use these steps: Open Start. Search for PowerShell, right-click the result, ... On Windows 11, you can still use Control Panel to change the IP settings for Ethernet or Wi-Fi adapters. To assign a static IP configuration through the Control Panel, use these steps: ...
The PowerShell function below can convert DHCP reservations for one or more server NICs to fixed IP configurations. Besides the IP address and subnet mask, it will also take care of other settings you would normally configure for a fixed IP, such as the default gateway and DNS servers.
Method 3: Set Up a Static IP Address using Command Prompt. If you like commands, then here are the instructions to change your Dynamic IP address to Static, via command line. 1. Open Windows Search, type command prompt, and select Run as administrator. Then, click Yes on the UAC prompt to proceed. 2.
To enable DHCP to obtain a TCP/IP configuration automatically on Windows 10, use these steps: Open Settings on Windows 10. Click on Network & Internet. Click on Ethernet or Wi-Fi. Click the network connection. Under the "IP settings" section, click the Edit button. Use the Edit IP settings drop-down menu and select the Automatic (DHCP) option.
Description. The Set-DnsClientServerAddress cmdlet sets one or more IP addresses for DNS servers associated with an interface. This cmdlet statically adds DNS server addresses to the interface. If this cmdlet is used to add DNS servers to the interface, then the DNS servers will override any DHCP configuration for that interface.
Change DNS servers with Win32_NetworkAdapterConfiguration. We can use PowerShell and Get-WmiInstance or Get-CimInstance (Win 8/2012 or later). For compatibility, we will be demonstrating using Get-WmiInstance. In our scenario, our old DNS servers were 192.168.1.11 and 192.168.1.12. We will be replacing these with 192.168.1.13 and 192.168.1.14.
Open the Network Connection Control Panel by running the command ncpa.cpl. Open the network connection properties > Internet Protocol Version 4 (TCP/IPv4) > Properties > specify the new IP address of the domain controller. If you change the subnet, change the default gateway IP. Click OK > OK to save changes.