Skip to content
Networking & DNSAdvanced

How to Set a Static IP Address Using PowerShell in Windows 10/11 and Windows Server – Complete Guide

A static IP address is an IP address manually assigned to a computer, server, network adapter, printer, or other network device instead of being automaticall...

BI
Bison Technical Team Enterprise IT specialists
Updated 19 May 2025 13 min read 202 total views
Structured technical guidanceSafety notes included where requiredSources listed below

A static IP address is an IP address manually assigned to a computer, server, network adapter, printer, or other network device instead of being automatically obtained from a DHCP server.

Static IP addresses are commonly required for:

Advertisement
  • Windows Servers
  • Remote Desktop (RDP) servers
  • File servers
  • Database servers
  • Tally servers
  • Application servers
  • Web servers
  • DNS servers
  • DHCP servers
  • Active Directory Domain Controllers
  • NAS devices
  • CCTV/NVR systems
  • Network printers
  • Virtual machines
  • Hyper-V hosts
  • Backup servers
  • Monitoring systems
  • Devices requiring port forwarding

Windows provides several ways to configure a static IP address. Besides the traditional graphical Network Connections interface, administrators can configure networking directly from PowerShell.

PowerShell is particularly useful when configuring servers, automating deployments, managing multiple machines, or creating repeatable network configuration scripts.


What Does a Static IP Configuration Contain?

A typical IPv4 configuration contains four important components:

Setting Example Purpose
IP Address 192.168.1.141 Unique address of the computer
Subnet Prefix /24 Defines the local network
Subnet Mask 255.255.255.0 Traditional representation of /24
Default Gateway 192.168.1.1 Router used to reach other networks
Primary DNS 8.8.8.8 Resolves domain names
Secondary DNS 8.8.4.4 Backup DNS resolver

For example:

IP Address:       192.168.1.141
Subnet Mask:      255.255.255.0
Prefix Length:    24
Default Gateway:  192.168.1.1
Primary DNS:      8.8.8.8
Secondary DNS:    8.8.4.4

Understanding Prefix Length

Modern Windows PowerShell networking commands commonly use CIDR prefix length rather than a traditional subnet mask.

Common examples are:

Subnet Mask Prefix Length
255.0.0.0 /8
255.255.0.0 /16
255.255.255.0 /24
255.255.255.128 /25
255.255.255.192 /26
255.255.255.224 /27
255.255.255.240 /28
255.255.255.248 /29
255.255.255.252 /30

Therefore:

-PrefixLength 24

normally corresponds to:

255.255.255.0

Supported Windows Versions

The commands discussed here are appropriate for modern versions of Windows containing the NetTCPIP and DnsClient PowerShell modules, including commonly deployed editions of:

  • Windows 10
  • Windows 11
  • Windows Server 2016
  • Windows Server 2019
  • Windows Server 2022
  • Windows Server 2025

The exact networking environment, permissions, policies, and available PowerShell modules should always be verified before deploying scripts across multiple systems.


Important Warning for Remote Servers

Be extremely careful when changing the IP configuration of a server through Remote Desktop, remote-support software, PowerShell Remoting, or another remote connection.

Changing any of the following incorrectly can immediately disconnect you:

  • IP address
  • Subnet
  • Default gateway
  • DNS configuration
  • Network adapter
  • Routing configuration

For important remote servers, preferably ensure that you have one of the following before changing networking:

  • Hypervisor console
  • VMware/Hyper-V console
  • Cloud provider console
  • iLO/iDRAC/IPMI access
  • Physical access
  • Alternate management interface
  • Another administrator available onsite

Do not blindly execute a network configuration script on a production server.


Step 1 – Open PowerShell as Administrator

Search for:

PowerShell

Right-click Windows PowerShell and select:

Run as administrator

Administrative privileges are normally required to modify network configuration.


Step 2 – Identify the Correct Network Adapter

Before assigning an IP address, determine the exact adapter name.

Run:

Get-NetAdapter

You may see adapters such as:

Ethernet
Ethernet 2
Wi-Fi
LAN
vEthernet (Default Switch)

Do not assume that the adapter is always called Ethernet.

You can also display useful adapter information with:

Get-NetAdapter | Format-Table Name, InterfaceDescription, Status, MacAddress, LinkSpeed

Look for the adapter whose status is:

Up

Step 3 – Check the Existing Network Configuration

Before changing anything, record the existing configuration.

Run:

Get-NetIPConfiguration

For a specific adapter:

Get-NetIPConfiguration -InterfaceAlias "Ethernet"

For additional IP information:

Get-NetIPAddress -InterfaceAlias "Ethernet"

You should note the existing:

  • IPv4 address
  • Subnet/prefix
  • Default gateway
  • DNS servers
  • Interface alias
  • Interface index

This information is extremely useful if you need to restore the previous configuration.


Step 4 – Check Whether DHCP Is Enabled

Run:

Get-NetIPInterface -InterfaceAlias "Ethernet" -AddressFamily IPv4

Check the Dhcp property.

It may show:

Enabled

or:

Disabled

A manually configured static IPv4 interface normally has DHCP disabled.


Step 5 – Check Whether the Desired IP Is Already in Use

Before assigning a static IP address, verify that another device is not already using it.

For example:

Test-Connection 192.168.1.141 -Count 2

However, an unsuccessful ping does not guarantee that an address is unused. A device may be online while blocking ICMP/ping.

For managed networks, the safest approach is to verify the IP against:

  • DHCP leases
  • Router/client list
  • IP address management records
  • Network documentation
  • ARP information
  • Existing static-IP allocation records

Duplicate IP addresses can cause intermittent or complete connectivity failures.


Basic PowerShell Static IP Script

The following example assigns:

Adapter: Ethernet
IP:      192.168.1.141
Mask:    255.255.255.0
Gateway: 192.168.1.1
DNS 1:   8.8.8.8
DNS 2:   8.8.4.4

Example:

$InterfaceAlias = "Ethernet"
$IPAddress      = "192.168.1.141"
$PrefixLength   = 24
$DefaultGateway = "192.168.1.1"
$DNSServers     = @("8.8.8.8","8.8.4.4")

Set-NetIPInterface `
    -InterfaceAlias $InterfaceAlias `
    -AddressFamily IPv4 `
    -Dhcp Disabled

New-NetIPAddress `
    -InterfaceAlias $InterfaceAlias `
    -IPAddress $IPAddress `
    -PrefixLength $PrefixLength `
    -DefaultGateway $DefaultGateway

Set-DnsClientServerAddress `
    -InterfaceAlias $InterfaceAlias `
    -ServerAddresses $DNSServers

Change all example values according to your network.


Improved PowerShell Script with Basic Safety Checks

For administrative use, checking the adapter before making changes is better than blindly executing the commands.

# ==========================================
# STATIC IPv4 CONFIGURATION
# ==========================================

$InterfaceAlias = "Ethernet"
$IPAddress      = "192.168.1.141"
$PrefixLength   = 24
$DefaultGateway = "192.168.1.1"
$DNSServers     = @("8.8.8.8", "8.8.4.4")

try {

    Write-Host "Checking network adapter..."

    $Adapter = Get-NetAdapter -Name $InterfaceAlias -ErrorAction Stop

    if ($Adapter.Status -ne "Up") {
        Write-Warning "Adapter '$InterfaceAlias' exists but is not currently Up."
    }

    Write-Host "Current network configuration:"
    Get-NetIPConfiguration -InterfaceAlias $InterfaceAlias

    Write-Host "Disabling DHCP..."
    Set-NetIPInterface `
        -InterfaceAlias $InterfaceAlias `
        -AddressFamily IPv4 `
        -Dhcp Disabled `
        -ErrorAction Stop

    Write-Host "Removing existing manually configured IPv4 addresses..."

    Get-NetIPAddress `
        -InterfaceAlias $InterfaceAlias `
        -AddressFamily IPv4 `
        -ErrorAction SilentlyContinue |
        Where-Object {
            $_.IPAddress -notlike "169.254.*"
        } |
        Remove-NetIPAddress -Confirm:$false -ErrorAction SilentlyContinue

    Write-Host "Creating static IPv4 address..."

    New-NetIPAddress `
        -InterfaceAlias $InterfaceAlias `
        -IPAddress $IPAddress `
        -PrefixLength $PrefixLength `
        -DefaultGateway $DefaultGateway `
        -ErrorAction Stop

    Write-Host "Configuring DNS servers..."

    Set-DnsClientServerAddress `
        -InterfaceAlias $InterfaceAlias `
        -ServerAddresses $DNSServers `
        -ErrorAction Stop

    Write-Host ""
    Write-Host "Static IP configuration completed."

    Get-NetIPConfiguration -InterfaceAlias $InterfaceAlias

}
catch {

    Write-Error "Network configuration failed: $($_.Exception.Message)"

}

Important

Even this improved script should be reviewed before use.

The address-removal portion intentionally changes the adapter's existing IPv4 configuration. On systems with multiple intentional IPv4 addresses, special routes, clustered applications, virtualization, or complex server networking, do not use a generic removal command without understanding the existing configuration.


Why New-NetIPAddress Is Used

New-NetIPAddress creates a new IPv4 or IPv6 address configuration on an interface.

Typical syntax:

New-NetIPAddress `
    -InterfaceAlias "Ethernet" `
    -IPAddress "192.168.1.141" `
    -PrefixLength 24 `
    -DefaultGateway "192.168.1.1"

The important parameters are:

-InterfaceAlias

Specifies the network adapter.

Example:

-InterfaceAlias "Ethernet"

-IPAddress

Specifies the static IP.

Example:

-IPAddress "192.168.1.141"

-PrefixLength

Specifies the subnet.

Example:

-PrefixLength 24

-DefaultGateway

Specifies the router/default gateway.

Example:

-DefaultGateway "192.168.1.1"

Configuring DNS with PowerShell

Use:

Set-DnsClientServerAddress

Example:

Set-DnsClientServerAddress `
    -InterfaceAlias "Ethernet" `
    -ServerAddresses ("8.8.8.8","8.8.4.4")

This assigns static DNS server addresses to the interface.


Public DNS Examples

Depending on your environment, commonly used public resolvers include:

Google Public DNS

8.8.8.8
8.8.4.4

Cloudflare Public DNS

1.1.1.1
1.0.0.1

Quad9

9.9.9.9
149.112.112.112

However, public DNS is not automatically the correct choice for every environment.


Important DNS Warning for Active Directory

If the machine is:

  • An Active Directory Domain Controller
  • A domain member
  • Dependent on internal DNS zones
  • Using internal server-name resolution

do not blindly configure Google or Cloudflare DNS.

Active Directory environments normally depend on the organization's internal DNS infrastructure.

Incorrect DNS configuration can cause problems with:

  • Domain logon
  • Group Policy
  • Active Directory replication
  • Server discovery
  • File shares
  • Kerberos authentication
  • Internal applications
  • Domain joins

Use the DNS architecture designed for your domain.


Verify the New Configuration

After making the changes, run:

Get-NetIPConfiguration -InterfaceAlias "Ethernet"

You can also run:

ipconfig /all

Confirm:

  • Correct IPv4 address
  • Correct subnet
  • Correct gateway
  • Correct DNS servers

Test the Local TCP/IP Stack

Run:

ping 127.0.0.1

If successful, the local TCP/IP stack is functioning.


Test the Local IP Address

Example:

ping 192.168.1.141

Replace the IP with the address assigned to the machine.


Test the Default Gateway

Example:

ping 192.168.1.1

If the gateway responds, basic LAN communication is working.

Note that some routers/firewalls may be configured not to answer ping requests.


Test Internet Connectivity Without DNS

Run:

Test-Connection 8.8.8.8 -Count 4

If an external IP is reachable but websites do not resolve, the problem may be DNS-related.


Test DNS Resolution

Run:

Resolve-DnsName microsoft.com

You can also use:

nslookup microsoft.com

If IP connectivity works but DNS resolution fails, check the configured DNS servers.


Complete Verification Commands

After configuration, these commands provide a useful diagnostic sequence:

Get-NetAdapter
Get-NetIPConfiguration
Get-NetIPAddress -AddressFamily IPv4
Get-DnsClientServerAddress
Test-Connection 127.0.0.1 -Count 2
Test-Connection 192.168.1.1 -Count 2
Resolve-DnsName microsoft.com

Change the gateway IP according to your network.


How to Change Only the DNS Servers

If the IP configuration is already correct and you only need to change DNS:

Set-DnsClientServerAddress `
    -InterfaceAlias "Ethernet" `
    -ServerAddresses ("1.1.1.1","1.0.0.1")

There is no need to recreate the IP address.


How to Reset DNS Servers

To return the DNS client configuration to its default/DHCP-provided DNS servers:

Set-DnsClientServerAddress `
    -InterfaceAlias "Ethernet" `
    -ResetServerAddresses

This is particularly useful when reverting an adapter to DHCP.


How to Return the Computer to DHCP

If you later want the computer to obtain its IPv4 configuration automatically:

Set-NetIPInterface `
    -InterfaceAlias "Ethernet" `
    -AddressFamily IPv4 `
    -Dhcp Enabled

Then reset DNS:

Set-DnsClientServerAddress `
    -InterfaceAlias "Ethernet" `
    -ResetServerAddresses

Depending on the previous static configuration, you may also need to remove the manually assigned static IPv4 address.

For example, first inspect:

Get-NetIPAddress `
    -InterfaceAlias "Ethernet" `
    -AddressFamily IPv4

Then remove only the specific static address that is no longer required.

Finally:

ipconfig /renew

Using Interface Index Instead of Adapter Name

Network adapters also have an InterfaceIndex.

Find it with:

Get-NetAdapter

or:

Get-NetIPConfiguration

You can then configure DNS using the interface index.

Example:

Set-DnsClientServerAddress `
    -InterfaceIndex 12 `
    -ServerAddresses ("8.8.8.8","8.8.4.4")

Using InterfaceIndex can be useful in automation where adapter names differ between computers, although the index itself should still be discovered and validated rather than blindly hard-coded.


Configuring Wi-Fi Instead of Ethernet

If the adapter is called:

Wi-Fi

change:

$InterfaceAlias = "Ethernet"

to:

$InterfaceAlias = "Wi-Fi"

Always confirm the real name with:

Get-NetAdapter

Common Errors and Troubleshooting

Error: No matching MSFT_NetAdapter objects found

Possible cause:

The adapter name is incorrect.

Check:

Get-NetAdapter

Then use the exact adapter alias.


Error: Instance DefaultGateway already exists

This can occur if an existing default route/gateway configuration conflicts with the new configuration.

Check:

Get-NetRoute -AddressFamily IPv4

Do not randomly delete routes on a production system. Determine which route belongs to the adapter and whether it is required.


Internet Stops Working After Setting Static IP

Check:

  1. IP address
  2. Prefix length
  3. Default gateway
  4. DNS servers
  5. Physical adapter status
  6. VLAN configuration
  7. Router configuration
  8. Firewall
  9. Duplicate IP address
  10. Network routes

Run:

Get-NetIPConfiguration

Local Network Works but Internet Does Not

A common cause is an incorrect default gateway.

For example, if your computer is:

192.168.10.50/24

but the router is actually:

192.168.10.1

using:

192.168.1.1

as the gateway will not work.


Internet by IP Works but Websites Do Not Open

This commonly indicates a DNS problem.

Test:

Test-Connection 8.8.8.8 -Count 2

Then:

Resolve-DnsName microsoft.com

If the first works and DNS resolution fails, investigate DNS configuration.


APIPA Address: 169.254.x.x

If Windows cannot obtain an IPv4 address from DHCP, it may automatically assign an address in the:

169.254.x.x

range.

This is known as Automatic Private IP Addressing (APIPA).

Seeing a 169.254.x.x address can indicate problems such as:

  • DHCP server unavailable
  • Network cable disconnected
  • VLAN problem
  • Wi-Fi association problem
  • DHCP relay failure
  • Network adapter issue

It does not normally provide normal routed network or Internet connectivity.


Static IP vs DHCP Reservation

A manually configured static IP is not the only way to ensure that a device keeps the same IP address.

Another option is a DHCP reservation.

Static IP

Configured directly on the Windows computer.

Advantages:

  • Does not depend on DHCP for addressing
  • Suitable for infrastructure servers in many designs
  • Simple in small controlled networks

Disadvantages:

  • Must be documented carefully
  • Greater chance of duplicate addresses if poorly managed
  • Network changes may require manual reconfiguration

DHCP Reservation

Configured on the DHCP server/router and normally linked to the device's MAC address.

Advantages:

  • Centralized management
  • Easier DNS/gateway changes
  • Lower risk of accidental address conflicts when properly managed
  • Easier management of many devices

Which approach is better depends on the network architecture.


Recommended Static IP Planning

Do not assign addresses randomly.

For example, an organization might document its network like this:

192.168.1.1       Router
192.168.1.2-20    Network Infrastructure
192.168.1.21-40   Servers
192.168.1.41-60   Printers
192.168.1.61-100  Reserved Devices
192.168.1.101-200 DHCP Clients

This is only an example. Actual address planning should match your environment.

Good IP documentation should record:

  • Device name
  • Hostname
  • IP address
  • MAC address
  • Subnet
  • Gateway
  • DNS
  • VLAN
  • Device purpose
  • Physical location
  • Date assigned
  • Administrator/owner

Recommended Procedure for Production Servers

For important servers, use this workflow:

  1. Identify the correct adapter.
  2. Record the current configuration.
  3. Confirm the new IP address.
  4. Verify that the new IP is not allocated elsewhere.
  5. Confirm subnet/prefix.
  6. Confirm default gateway.
  7. Confirm correct DNS servers.
  8. Confirm VLAN/network segment.
  9. Ensure console or recovery access is available.
  10. Apply the new configuration.
  11. Verify the IP.
  12. Test the gateway.
  13. Test DNS.
  14. Test Internet or WAN connectivity if required.
  15. Test server applications.
  16. Test RDP/remote management.
  17. Update network documentation.

Example: Small Office Network

Suppose a server needs:

Server IP:       192.168.10.20
Subnet Mask:     255.255.255.0
Gateway:         192.168.10.1
DNS 1:           192.168.10.10
DNS 2:           192.168.10.11
Adapter:         Ethernet

PowerShell:

$InterfaceAlias = "Ethernet"

Set-NetIPInterface `
    -InterfaceAlias $InterfaceAlias `
    -AddressFamily IPv4 `
    -Dhcp Disabled

New-NetIPAddress `
    -InterfaceAlias $InterfaceAlias `
    -IPAddress "192.168.10.20" `
    -PrefixLength 24 `
    -DefaultGateway "192.168.10.1"

Set-DnsClientServerAddress `
    -InterfaceAlias $InterfaceAlias `
    -ServerAddresses ("192.168.10.10","192.168.10.11")

This example uses internal DNS addresses, which may be appropriate for an Active Directory environment.


PowerShell vs GUI Configuration

Feature PowerShell Windows GUI
Single computer Yes Yes
Automation Excellent Poor
Multiple systems Excellent Manual
Scripting Yes No
Repeatability Excellent Moderate
Beginner friendly Moderate Excellent
Remote administration Excellent Limited
Documentation/auditing Excellent Manual

PowerShell is especially useful for IT administrators managing multiple systems.


Security Considerations

Changing IP configuration is an administrative operation.

Follow these practices:

  • Run scripts only from trusted sources.
  • Review scripts before executing them.
  • Do not blindly run copied PowerShell commands.
  • Verify adapter names.
  • Verify IP addresses.
  • Avoid IP conflicts.
  • Record the previous configuration.
  • Use appropriate internal DNS on domain networks.
  • Maintain network documentation.
  • Ensure recovery access exists before modifying remote servers.
  • Test scripts on non-production machines before mass deployment.

Frequently Asked Questions (FAQ)

1. Can PowerShell assign a static IP address?

Yes. Windows provides networking cmdlets such as New-NetIPAddress, Set-NetIPInterface, and Set-DnsClientServerAddress.

2. Do I need Administrator rights?

Normally yes. Changing system network configuration requires elevated privileges.

3. How do I find my adapter name?

Run:

Get-NetAdapter

4. How do I check my current IP configuration?

Run:

Get-NetIPConfiguration

or:

ipconfig /all

5. What does PrefixLength 24 mean?

A /24 IPv4 network normally corresponds to:

255.255.255.0

6. Can I configure DNS separately?

Yes.

Set-DnsClientServerAddress `
    -InterfaceAlias "Ethernet" `
    -ServerAddresses ("8.8.8.8","8.8.4.4")

7. Can I use Cloudflare DNS?

Yes, where appropriate:

1.1.1.1
1.0.0.1

But domain environments may require internal DNS servers instead.

8. Should a Domain Controller use Google DNS directly?

Generally, an Active Directory DNS design should use the appropriate internal/domain DNS infrastructure rather than blindly configuring public DNS on the network adapter.

9. Can changing the IP disconnect RDP?

Yes. Changing the address, gateway, subnet, adapter, or routing of a remote server can immediately terminate connectivity.

10. How do I switch back to DHCP?

Use:

Set-NetIPInterface `
    -InterfaceAlias "Ethernet" `
    -AddressFamily IPv4 `
    -Dhcp Enabled

and reset DNS:

Set-DnsClientServerAddress `
    -InterfaceAlias "Ethernet" `
    -ResetServerAddresses

Also remove any unwanted manually configured static IPv4 address after verifying which address should be removed.

11. Why do I have a 169.254.x.x address?

Windows may assign an APIPA address when it cannot obtain an IPv4 address from DHCP.

12. Can the same script be used on Wi-Fi?

Yes, provided you specify the correct adapter alias, such as:

$InterfaceAlias = "Wi-Fi"

13. Can I configure multiple DNS servers?

Yes.

Example:

-ServerAddresses ("8.8.8.8","8.8.4.4")

14. Can a computer have multiple static IP addresses?

Yes. Windows can have multiple IP addresses assigned to an interface, which is one reason administrators should be careful with scripts that indiscriminately remove existing addresses.

15. Why does the LAN work but Internet access fail?

An incorrect default gateway, routing issue, firewall policy, VLAN problem, or upstream network issue may be responsible.

16. Why does ping to an IP work but websites fail?

DNS resolution may be failing.

Test:

Resolve-DnsName microsoft.com

17. Should I use a static IP or DHCP reservation?

Both can provide stable addressing. Static addressing is configured on the endpoint; DHCP reservations are centrally managed by a DHCP server. The better choice depends on your network architecture.

18. Can I use these commands on Windows Server?

Yes. These networking PowerShell cmdlets are widely used for Windows Server administration.

19. Do I need to restart Windows after changing the static IP?

Normally, a full Windows restart is not required. Network configuration changes generally take effect immediately.

20. Is it safe to remove all existing IPv4 addresses before adding a new one?

Not universally. A server may intentionally have multiple IP addresses or specialized networking. Inspect the configuration first and remove only addresses you know are safe to remove.


Conclusion

PowerShell provides a fast and powerful method for configuring static IPv4 addresses on Windows computers and servers.

The core commands administrators should understand are:

Get-NetAdapter
Get-NetIPConfiguration
Get-NetIPAddress
Get-NetIPInterface
Set-NetIPInterface
New-NetIPAddress
Set-DnsClientServerAddress

The most important part of static-IP configuration is not simply running a script. Administrators should first verify the adapter, IP address, subnet, gateway, DNS servers, DHCP status, and existing network configuration.

Extra care is essential when modifying remote or production servers because an incorrect network configuration can immediately make the system inaccessible.

 

YOUR FEEDBACK

Was this guide useful?

Your answer helps us keep BISONKB accurate and practical.

THE BISON BRIEF

Practical IT knowledge, once a week.

New troubleshooting guides, scripts and infrastructure notes. No noise.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.