Powershell - Managing IP configuration of network interfaces
To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!
Following on from the previous article on commands for viewing and changing the status and configuration of network interfaces, here is a set of commands for viewing and changing the IP settings of network interfaces.
# Display IP configurationGet-NetIPConfiguration
# Displays the IP configuration of all interfaces, even disconnected onesGet-NetIPConfiguration -All
# Specify an interface via its indexGet-NetIPConfiguration -InterfaceIndex 12 | fl *
# Specify an interface via its nameGet-NetIPConfiguration -InterfaceAlias Ethernet
# Display more information about the IP configurationGet-NetIPConfiguration -Detailed
# Define a fixed IPv4, mask and default gatewayNew-NetIPAddress 192.168.0.1 -PrefixLength 24 -InterfaceAlias Ethernet -DefaultGateway 192.168.0.254
# Note: By default, the IP is stored in two locations:# - ActiveStore: Configuration used until the computer is shut down# - PersistentStore: Configuration loaded (in the Active store) when the computer is started.New-NetIPAddress 192.168.0.1 -PrefixLength 24 -InterfaceAlias Ethernet -DefaultGateway 192.168.0.254 -PolicyStore ActiveStore
# If you don't want it to appear in the DNS# and not be used as the main address, add -SkipAsSource $TrueNew-NetIPAddress -InterfaceAlias ethernet -IPAddress 10.0.0.201 -PrefixLength 24 -AddressFamily IPv4 -SkipAsSource $True
# Define DNSSet-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses 192.168.0.254,192.168.0.253
# Display DNS configurationGet-DnsClientServerAddress
# Redefines DNS with default values (those of DHCP)Set-DnsClientServerAddress -InterfaceAlias Ethernet -ResetServerAddresses
# Set a fixed IPv6, prefix and default gatewayNew-NetIPAddress -InterfaceAlias Ethernet -IPAddress FD00::2 -PrefixLength 64 -DefaultGateway FD00::1
# Enable DHCP on a network interfaceSet-NetIPInterface -InterfaceAlias Ethernet -Dhcp Enabled# Note: this also removes the fixed IP but not the gateway
# remove the gatewayRemove-NetRoute -InterfaceAlias Ethernet -NextHop 192.168.0.254
# Disable DHCP on a network interfaceSet-NetIPInterface -InterfaceAlias Ethernet -Dhcp Disabled# Note: if you set a fixed IP, DHCP is automatically disabled.
# Display interface metrics, MTU and status for IPv4Get-NetIPInterface -AddressFamily IPv4# Or IPv6Get-NetIPInterface -AddressFamily IPv6
# Modify the metric of an interfaceSet-NetIPInterface -InterfaceAlias Ethernet -InterfaceMetric 20
# Display the IPv4 addresses configured for an interfaceGet-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Ethernet | Select-Object InterfaceAlias, IPAddress, PrefixLength
# Delete an IP without requesting confirmationGet-NetIPAddress -AddressFamily IPv4 -InterfaceAlias Ethernet | Remove-NetIPAddress -AddressFamily IPv4 -Confirm:$false
# Display global IPv4 protocol configurationGet-NetIPv4Protocol | Select-Object -Property *
# Display global IPv6 protocol configurationGet-NetIPv6Protocol | Select-Object -Property *
# It is of course possible to modify the global configuration of IPv4 and IPv6 protocols using the following commandsSet-NetIPv4Protocol# or for IPv6Set-NetIPv6Protocol
Related links
Powershell - Testing network connectivity and port accessibility
Testing network connectivity and port accessibility with PowershellPowershell - Display network connections (equivalent to netstat)
Display network connections (listening ports, active connections...)Powershell - Testing name resolution (equivalent to nslookup)
Powershell commands to test name resolution (equivalent to nslookup)Powershell - View and manage DNS configuration of network interfaces
Powershell commands to display and manage DNS configuration of network interfacesPowershell - Managing IP configuration of network interfaces
Powershell commands to view and modify the IP configuration of network interfacesPowershell - Managing the status and configuration of network interfaces
Powershell commands to view and modify the status and configuration of network interfaces (disable IPv6, enable/disable an interface)
Follow me on
Support me
Last content
Powershell - Testing network connectivity and port accessibility
Powershell - Display network connections (equivalent to netstat)
Powershell - Testing name resolution (equivalent to nslookup)
Powershell - View and manage DNS configuration of network interfaces
Powershell - Managing IP configuration of network interfaces
Powershell - Managing the status and configuration of network interfaces
Powershell and the Left Hand Side
Powershell - Managing disks, partitions and volumes