LOGO

Change IP Address with PowerShell: A Step-by-Step Guide

May 14, 2012
Change IP Address with PowerShell: A Step-by-Step Guide

Changing Your IP Address with PowerShell

Previously, we demonstrated altering your IP address using the command prompt, a process involving extensive netsh commands. Now, we'll achieve the same result in PowerShell, streamlining the procedure and reducing complexity.

Prerequisites

It's important to note that the commands detailed below were introduced in PowerShell version 3. Consequently, they necessitate Windows 8 or a later operating system.

An administrative command prompt or PowerShell session is also required to execute these commands successfully.

Target Audience

This guide is geared towards users with a foundational understanding of IP Addressing and CIDR notation.

Some technical familiarity will be beneficial for optimal comprehension and implementation.

The following steps will allow you to modify your network configuration efficiently using PowerShell.

This method offers a more concise and manageable alternative to traditional netsh commands.

Modifying Your IP Address

Historically, altering IP addresses involved complex Windows Management Instrumentation (WMI) classes within older PowerShell iterations, causing considerable frustration for many users. However, PowerShell v3 introduced the NetTCPIP module, streamlining this process and bringing core functionality directly into native PowerShell.

Although initially somewhat perplexing due to limited documentation, the system becomes more intuitive with practical guidance.

Utilizing New-NetIPAddress

IP address modification is now achievable through the New-NetIPAddress cmdlet. This cmdlet features numerous parameters, some of which are not fully detailed within the standard Get-Help documentation.

New-NetIPAddress --InterfaceAlias "Wired Ethernet Connection" --IPv4Address "192.168.0.1" --PrefixLength 24 -DefaultGateway 192.168.0.254

This command operates under specific assumptions:

  • The network interface designated for IP address alteration is named "Wired Ethernet Connection."
  • A static IP address of 192.168.0.1 is to be assigned.
  • A subnet mask equivalent to 255.255.255.0 is required, represented as /24 in CIDR notation.
  • The default gateway will be configured as 192.168.0.254.

Naturally, these settings should be adjusted to align with the specific addressing scheme of your network environment.

Remember to adapt the parameters to reflect your network’s unique configuration.

Configuring Your DNS Settings

A further, potentially complex step involves utilizing the DNSClient module for managing your Domain Name System configurations. Altering your DNS server settings is accomplished through the following command:

Set-DnsClientServerAddress -InterfaceAlias "Wired Ethernet Connection" -ServerAddresses 192.168.0.1, 192.168.0.2

This command specifically designates 192.168.0.1 as the primary DNS server and 192.168.0.2 as the secondary DNS server for the network interface named "Wired Ethernet Connection". The process is relatively straightforward once the module is understood.

Understanding the Command

The Set-DnsClientServerAddress cmdlet is central to this configuration. It allows for precise control over the DNS servers utilized by your network connection.

  • -InterfaceAlias: This parameter specifies the network adapter to which the DNS settings will be applied.
  • -ServerAddresses: This parameter defines the IP addresses of the primary and secondary DNS servers, separated by a comma.

Successfully executing this command ensures your system utilizes the specified DNS servers for resolving domain names.

In essence, modifying your DNS settings through the DNSClient module is a concise procedure. It provides a direct method for controlling how your network connection resolves internet addresses.

#PowerShell#IP address#change IP#network configuration#command line#IP address change