Batch processing to switch inside and outside IP

Source: Internet
Author: User

Because of the transformation of the working environment or the internal and external network switching, so that the IP address has to be frequently replaced, in order to avoid the trouble of changing the IP address, with a DOS command to do a batch file to achieve the IP address and DNS address rapid changes.

I. Introduction of the Order

The DOS commands used here are:netsh interface ip set (address/dns) or shorthand for netsh int ip set (address/dns)

Usage format:

netsh interface ip set address[name=]<string>
[[Source=]dhcp |
[source=] static [ADDR=]IP address [mask=]ip Subnet mask]
[[Gateway=]<ip Address>|none [Gwmetric=]integer]

netsh interface ip set DNS [name=]<string> [source=]dhcp|static [Addr=]<ip Address>|none
[[Register=]none|primary|both]

Parameter description:

Name-interface names.

Source -one of the following values:
DHCP: For the specified interface, set the IP address or DNS server to be configured with DHCP.
Static: Sets the IP address or DNS server to be set using a local static configuration.

Gateway -One of the following values:
<ip ADDRESS>: The specified default gateway for the IP address you set.
None: Default gateway is not set.

gwmetric -metric for the default gateway. If the gateway is set to ' None ', this field should not be set.

The following options are set only when ' source ' is ' static ':

Addr -Specifies the IP address of the interface.
Mask -Specifies the subnet mask for the IP address.

Register -one of the following values:
None: Disable dynamic DNS registration.
Primary: Registered only under the primary DNS suffix.
Both: Registered under the primary DNS suffix, also registered under a specific connection suffix.

Second, the production of batch documents (in the case of internal and external network)

Set "local connection" on the network when the IP address for automatic acquisition, DNS 202.99.224.8, the upper intranet is the IP address for 192.168.1.123 mask 255.255.255.0 Gateway 192.168.1.1,dns for automatic acquisition.

the code for the extranet is

@echo off
Set dns=202.99.224.8

netsh interface ip set address name= "Local Area Connection" Source=dhcp
netsh interface ip set DNS name= "Local Area Connection" Source=static addr=%dns%

Copy the code into a text, save the text as "extranet Ip.bat" (the filename is optional and the extension must be bat).

the code on the intranet

@echo off
Set name= "Local Area Connection"
Set ipaddress=192.168.1.123
Set mask=255.255.255.0
Set gateway=192.168.1.1

netsh interface ip set address name=%name% source=static addr=%ipaddress% mask=%mask% gateway=%gateway% 1
netsh interface ip set DNS name= "Local Area Connection" Source=dhcp

Copy the code into a text and save the text as an "intranet Ip.bat."

On the intranet when the intranet network cable, the implementation of "intranet Ip.bat", the external network when the network cable, the implementation of the "External network ip.bat."

Everyone in use according to their own situation to change the root IP address, mask, gateway and DNS.

//////////////////////////////////////////

/////////////////////////////////////////

Echo #设静态IP
netsh interface ip set address name= "Local Area Connection" Source=static addr=192.168.1.20 mask=255.255.255.0
Echo #设默认网关
netsh interface ip set address name= "Local Area Connection" gateway=192.168.1.1 gwmetric=0
Echo #设首选dns
netsh interface ip set DNS name= "Local Area Connection" Source=static addr=192.168.1.1 register=primary
Echo #设备用dns
netsh interface ip add DNS name= "Local Area Connection" addr=211.90.88.129 index=2
netsh interface ip set wins name= "Local Area Connection" Source=static Addr=none
Echo #
echo #显示 "Local Area Connection" configuration results
netsh interface ip show config local Area Connection
Echo #
Echo # "Local Area Connection" interface IP configuration
Echo #设自动获取ip
netsh interface ip set address name= "Local Area Connection" Source=dhcp
Echo #设自动获取dns
netsh interface ip set DNS name= "Local Area Connection" Source=dhcp register=primary
echo netsh interface ip set wins name= "Local Area Connection" Source=dhcp

echo #显示 "Local Area Connection" configuration results
netsh interface ip show config local Area Connection
Echo # interface IP configuration End

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.