Automatic IP Switch script in Windows

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.