When using a computer in different environments, you often need to switch the IP address. Using the netsh interface ip command, you can easily switch the IP address and DNS:
The netsh interface ip Address has the following commands:
Add-add a configuration item in a table.
Delete-delete a configuration item from a table.
Dump-displays a configuration script.
Help-display the command list.
Install-install the IP protocol.
Reset-reset IP configuration.
Set-set configuration information.
Show-display information.
Uninstall-uninstall the IP protocol.
Netsh interface IP set has the following commands:
Set address-set the IP address or default gateway to the interface.
Set compartment-Modify the Segment configuration parameters.
Set dnsservers-set the DNS server mode and address.
Set dynamicportrange-Modify the port range used by the State port allocation.
Set global-modify general global configuration parameters.
Set interface-Modify IP interface configuration parameters.
Set neighbors-set the neighbor address.
Set route-Modify route parameters.
Set subinterface-Modify sub-interface configuration parameters.
Set winsservers-set the WINS server mode and address.
Simple Example 1: set a fixed IP address and save it as a bat file
@ Echo off
@ Rem: Set the IP address to 192.168.0.1, And the subnet mask to 255.255.0. The default gateway is 192.168.0.254.
Netsh interface ip set address local static 192.168.0.1 255.255.255.0 192.168.0.254
@ Rem set the preferred DNS server 192.168.0.254
Netsh interface ip set dns local 192.168.0.254
@ Rem add DNS server 202.106.196.115
Netsh interface ip add dns local 202.106.196.115 index = 2
Example 2: Get automatically
@echo off netsh interface ip set address name="local" source=dhcp netsh interface ip set dns name="local" source=dhcp