How to Set a Dynamic IP Address with PowerShell
A dynamic IP address is an IP address assigned automatically by a DHCP server, which is a service that manages the distribution of IP addresses on the network. Dynamic IP addresses are useful if you don’t want to bother setting IP addresses manually, or if you frequently switch networks. To set a dynamic IP address with PowerShell, follow these steps:
- Run the following command in PowerShell to remove any static IP addresses that may have been previously assigned:
Remove-NetIPAddress -InterfaceAlias “Ethernet” -Confirm:$false
This command deletes the existing IP address object for the specified network interface. The -Confirm:$false parameter disables the confirmation normally requested by PowerShell before deleting the object.
- Run the following command in PowerShell to enable DHCP for the specified network interface:
Set-NetIPInterface -InterfaceAlias “Ethernet” -Dhcp Enabled
This command changes the DHCP settings for the specified network interface. The -Dhcp Enabled parameter specifies that DHCP should be enabled for that network interface.
- Run the following command in PowerShell to request a new IP address from the DHCP server:
Renew-NetIPAddress -InterfaceAlias “Ethernet”
This command will update the IP address for the specified network interface by requesting a new IP address from the DHCP server. You can use this command if you want to replace your IP address with another available one.
- Run the following command in PowerShell to check if the dynamic IP address has been assigned successfully:
Get-NetIPAddress -InterfaceAlias “Ethernet”
This command displays information about the IP address assigned to the specified network interface. You can see that the IP address, subnet mask, and gateway match those provided by the DHCP server.
In this article, we’ve discussed how to set an IP address with PowerShell, either statically or dynamically. We’ve also seen some PowerShell commands that are useful for managing network settings in Windows. Using PowerShell, you can set IP addresses easily and quickly, without having to open the Control Panel or Network and Sharing Center. Hope this article was helpful for those of you who want to learn more about PowerShell and networking. Thanks for reading.