Automatic TCP/IP configuration for netsh Batch Processing

Source: Internet
Author: User

Use the netsh.exe command to Configure TCP/IP

Do you know what netsh.exe can do for you? If you do not know.

First, it displays the settings of your TCP/IP protocol. In the Command Prompt window (CMD. EXE), enter the following command:
Netsh interface IP show config

You can also use it to change the IP address of a computer or configure other properties of TCP/IP. For example, you want to specify a static IP address for the "local connection" of the computer.
Address: 192.168.0.100, set its subnet mask? 55.255.255.0, and specify the default gateway as 192.168.0.1. You only need to enter
Column command:
Netsh interface IP Set address name = "Local Area Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1

(Note: This is a complete command. Do not wrap it when entering it .)

Coming soon
Quickly switch the TCP/IP settings to meet the needs of different networks. Ntesh.exe can export different TCP/IP settings to different configuration files, and then import the configuration files as needed
To change the corresponding settings.

For example, your laptop is now connected to network 1 and the corresponding network settings have been completed. In this case, you can enter the following in the Command Prompt window:
Netsh-C interface dump> C: location1.txt

Use this command to export the corresponding TCP/IP settings to a text file named location1.txt in C. Similarly, you can export the settings of different network environments to different configuration files. To access different networks, you only need to use the following command:
Netsh-f c: location1.txt (or: netsh-f c: location2.txt)

In addition, you can configure the network adapter through netsh.exe to automatically obtain the IP address from the DHCP server. The command is as follows:
Netsh interface IP Set address "Local Area Connection" DHCP

You can also configure wins:
Netsh interface IP Set wins "Local Area Connection" static 192.168.0.200

You can also use netsh.exe to dynamically obtain DNS settings for the network adapter:
Netsh interface IP Set DNS "Local Area Connection" DHCP

As you know, netsh.exe is a useful tool for customizing TCP/IP Settings.
Bytes ----------------------------------------------------------------------------------------------------------------
How to modify network connections using batch files

How to modify network connections using batch filesFavorites


New article: Calling Windows commands in Java | old article: is the great troubles of struts really not suitable for big systems?



I. How to modify network connections using batch files

Save the following script as a batch processing file, such as lan. bat, and then double-click to execute the file.
Modification is required,
Each row below can be independent. If no configuration is available, the row will be removed,
For example, if the backup DNS does not exist, remove the line,

Netsh interface IP Set address name = "Local Connection" Source = static ADDR = 192.168.0.241 mask = 255.255.255.0
Netsh interface IP Set address name = "Local Connection" Gateway = 192.168.0.254 gwmetric = 0
Netsh interface IP Set DNS name = "Local Connection" Source = static ADDR = 202.96.128.68 register = primary
Netsh interface IP add DNS name = "Local Connection" ADDR = 61.144.56.100 Index = 2
Netsh interface IP Set wins name = "Local Connection" Source = static ADDR = none

Note: This script is not applicable to all machines and needs to be adjusted accordingly.
Where
ADDR is the IP address (in the first line)
The mask is a subnet mask (located in the first line)
Gateway is the gateway by default (in the second line)
DNS name = "Local Connection" Source = static ADDR is first elected as the DNS server (in the third line)
Add DNS name = "Local Connection" is used as a backup DNS server (on the fourth line)

 

Ii. How to easily obtain the network connection script of the Local Machine

[Start]/[run]/enter [cmd]/enter [netsh interface dump]
You can see the "#" Local Connection "interface IP configuration"
Copy it, or use the [netsh interface dump> C:/lan.txt] command to export it to the C:/lan.txt file.
The exported result is as follows:

# "Local Connection" interface IP configuration


Set address name = "Local Connection" Source = static ADDR = 192.168.0.241 mask = 255.255.255.0
Set address name = "Local Connection" Gateway = 192.168.0.254 gwmetric = 0
Set DNS name = "Local Connection" Source = static ADDR = 202.96.128.68 register = primary
Add DNS name = "Local Connection" ADDR = 61.144.56.100 Index = 2
Set wins name = "Local Connection" Source = static ADDR = none

Add the netsh interface IP address in front of each line and save it as a batch file, such as lan. bat. Then double-click the file to execute it.

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.