- Overview
- Variable Definitions
- Step 1: Check Current Network Configuration
- Step 2: Switch from DHCP to Static IP
- Step 3: Configure DNS Servers
- Step 4: Set Priority in Multi-NIC Environments
- Step 5: Verify Connectivity
- Step 6: Disable IPv6 (Optional)
- Step 7: Best Practices
- Enable or Disable a Network Adapter
- Remove Static IP and Revert to DHCP
- Conclusion
Overview
This article explains how to manage Windows Server network configuration consistently using PowerShell.
It covers static IP setup, DNS configuration, routing priority adjustment, and key considerations when managing multiple NICs.
Variable Definitions
| Variable | Example | Description |
|---|---|---|
<<INTERFACE_ALIAS>> |
Ethernet0 |
Target network adapter name |
<<IP_ADDRESS>> |
192.168.10.100 |
Static IP address |
<<PREFIX_LENGTH>> |
24 |
Subnet prefix length (e.g., 255.255.255.0 → 24) |
<<GATEWAY>> |
192.168.10.1 |
Default gateway |
<<DNS1>> |
192.168.10.10 |
Primary DNS server |
<<DNS2>> |
8.8.8.8 |
Secondary DNS server (optional) |
Step 1: Check Current Network Configuration
List existing NICs and review their IP configurations.
# List adapters
Get-NetAdapter | Select-Object Name, Status, MacAddress, LinkSpeed
# Show IP configuration
Get-NetIPAddress | Select-Object InterfaceAlias, IPAddress, PrefixLength, DefaultGateway, PrefixOrigin
| OriginType | Meaning | Notes |
|---|---|---|
| Manual | Manually assigned static address | Explicitly configured via PowerShell or GUI |
| DHCP | Automatically assigned by DHCP server | Enabled with Set-NetIPInterface -Dhcp Enabled |
| WellKnown | System-reserved link-local or APIPA address | Used when DHCP is unavailable (e.g., 169.254.x.x) |
Step 2: Switch from DHCP to Static IP
Disable DHCP and assign a fixed IP address.
# Disable DHCP
Set-NetIPInterface -InterfaceAlias "<<INTERFACE_ALIAS>>" -Dhcp Disabled
# Remove existing DHCP address (if any)
Get-NetIPAddress -InterfaceAlias "<<INTERFACE_ALIAS>>" -AddressFamily IPv4 |
Where-Object { $_.PrefixOrigin -eq "Dhcp" } |
Remove-NetIPAddress -Confirm:$false
# Set static IP
New-NetIPAddress `
-InterfaceAlias "<<INTERFACE_ALIAS>>" `
-IPAddress "<<IP_ADDRESS>>" `
-PrefixLength <<PREFIX_LENGTH>> `
-DefaultGateway "<<GATEWAY>>"
Note:
UseRemove-NetIPAddressonly to remove DHCP-assigned addresses.
Avoid running this command on a remotely connected NIC to prevent connection loss.
Step 3: Configure DNS Servers
Specify DNS servers and confirm the settings.
# Configure DNS
Set-DnsClientServerAddress `
-InterfaceAlias "<<INTERFACE_ALIAS>>" `
-ServerAddresses ("<<DNS1>>","<<DNS2>>")
# Verify DNS settings
Get-DnsClientServerAddress -InterfaceAlias "<<INTERFACE_ALIAS>>"
Clear the DNS cache and test name resolution:
Clear-DnsClientCache
Resolve-DnsName "www.microsoft.com"
Step 4: Set Priority in Multi-NIC Environments
When multiple networks exist, manually adjust routing priority (InterfaceMetric).
Smaller values indicate higher priority.
# Check current metrics
Get-NetIPInterface | Sort-Object -Property InterfaceMetric |
Select-Object InterfaceAlias, AddressFamily, InterfaceMetric
# Set preferred NIC priority (management NIC first)
Set-NetIPInterface -InterfaceAlias "<<INTERFACE_ALIAS>>" -InterfaceMetric 10
Recommended Values:
- Management LAN:
10- Backup LAN:
20–50- Cluster / iSCSI traffic:
100or higher
Step 5: Verify Connectivity
Check network reachability and DNS resolution.
# Test gateway connectivity
Test-Connection "<<GATEWAY>>" -Count 4
# Test DNS name resolution
Resolve-DnsName "www.microsoft.com"
Tip:
If DNS settings are not applied properly, restart the DNS client service:net stop dnscache && net start dnscache
Step 6: Disable IPv6 (Optional)
By default, Windows Server enables both IPv4 and IPv6.
If IPv6 is unused in your environment, disable it to prevent unnecessary route advertisements and inconsistent name resolution.
# Check IPv6 binding status
Get-NetAdapterBinding `
-InterfaceAlias "<<INTERFACE_ALIAS>>" `
-ComponentID "ms_tcpip6"
# Disable IPv6
Disable-NetAdapterBinding `
-InterfaceAlias "<<INTERFACE_ALIAS>>" `
-ComponentID "ms_tcpip6" `
-PassThru
# Verify again
Get-NetAdapterBinding `
-InterfaceAlias "<<INTERFACE_ALIAS>>" `
-ComponentID "ms_tcpip6"
Re-enable IPv6 if required:
Enable-NetAdapterBinding `
-InterfaceAlias "<<INTERFACE_ALIAS>>" `
-ComponentID "ms_tcpip6"
Step 7: Best Practices
- Fix NIC Names
Prevent automatic renaming by assigning a management label:Rename-NetAdapter -Name "<<INTERFACE_ALIAS>>" -NewName "LAN-Primary" - Remove Unnecessary Routes
Avoid duplicate or invalid routes by explicitly cleaning them:Get-NetRoute -AddressFamily IPv4 Remove-NetRoute -DestinationPrefix "0.0.0.0/0" -InterfaceAlias "BackupNIC" -Confirm:$false
Enable or Disable a Network Adapter
# Disable adapter
Disable-NetAdapter -Name "<<INTERFACE_ALIAS>>" -Confirm:$false
# Enable adapter
Enable-NetAdapter -Name "<<INTERFACE_ALIAS>>"
Remove Static IP and Revert to DHCP
Remove-NetIPAddress -InterfaceAlias "<<INTERFACE_ALIAS>>" -IPAddress "<<IP_ADDRESS>>" -Confirm:$false
Set-NetIPInterface -InterfaceAlias "<<INTERFACE_ALIAS>>" -Dhcp Enabled
Conclusion
PowerShell provides a precise and repeatable way to manage Windows Server network configurations.
In multi-NIC environments, routing priority control and explicit DNS configuration are critical for stable operations.
Implement script-based configuration from the start to streamline rebuilds and deployments across environments.
