Netsh command to switch network lines

Source: Internet
Author: User
Assume that there are currently two Internet connections, one is CERNET One is for China Telecom Broadband , You can switch the line by setting different gateways of the local Nic. It is often necessary to switch between two lines. It is troublesome to modify the gateway each time, so you can use netsh to switch the IP address.

Netsh is a self-contained command in windows. It is used to set Nic parameters, such as IP address, subnet mask, gateway, and DNS, in the command line State. It has powerful functions, previously, I encountered a problem where the Network Setting window of a machine could not be opened and the NIC IP address could not be set. The problem was solved by using the netsh command. The following describes how to switch an IP address through netsh:

1. Right-click "network neighbor → properties" on the desktop and set the TCP/IP attributes used by the "local connection" Nic in CERNET. After setting, enter the command line mode and enter the following command: netsh-C interface dump> C:/jy20.txt

2. Set the TCP/IP attribute of the NIC to the network configuration used in the bandwidth in the same way. Run the following command in the command line: netsh-C interface dump> C:/kdw.txt

3. Use notepad to create a batch processing file named jyw. bat, content: netsh-f c:/jy20.txt; create another batch processing file kdw. bat, input content: netsh-f c:/kdw.txt. Right-click a shortcut on the desktop, and click browse to direct the project to jyw. bat, enter the shortcut name "Education Network Configuration"; repeat the previous step and point the project location to kdw. BAT to create a "Broadband configuration" shortcut.

4. If you are in the education network, double-click the "Broadband configuration" shortcut with the mouse to switch the network to the broadband network. On the contrary, you can easily switch to the education network.

Netsh usage:
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 192.168.0.100 for the "local connection" of your computer, set its subnet mask to 255.255.255.0, and specify the default gateway as 192.168.0.1, you only need to enter the following command in the Command Prompt window:
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 .)
To 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:/a.txt

Use this command to export the corresponding TCP/IP settings to a text file named a.txt under 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:/B .txt (or: netsh-f c:/B .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

Netsh.exe is a useful tool for customizing TCP/IP Settings.

No one will doubt the strength of the netsh command, and experienced administrators will be deeply aware of this;

Netsh Tool
Netsh.exe can be used to configure TCP/IP Settings: IP address, subnet mask, default gateway, DNS and wins address, and other options.
3.1 display TCP/IP Settings
Netsh interface IP show config

3.2 configure IP addresses
Netsh interface IP Set address name = "Local Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1

3.3 export your current IP settings
Netsh-C interface dump> C:/location1.txt

3.4 import your IP settings
Netsh-f c:/location1.txt
Or netsh exec C:/location2.txt

3.5 automatically obtain the IP address and DNS address
Netsh interface IP Set address "Local Connection" DHCP
Netsh interface IP Set DNS "Local Connection" DHCP

3.6 configure DNS and wins addresses
Netsh interface IP Set DNS "Local Connection" static 192.168.0.200
Netsh interface IP Set wins "Local Connection" static 192.168.0.200

Appendix: netsh Command commands
The following commands are valid:

Commands in this context:
..-Move to the context level of the previous layer.
? -Displays the command list.
Abort-Discard the changes made in offline mode.
Add-Add a configuration project to the project list.
Alias-Add an alias
Bridge-Change to 'netsh bridge'Context.
Bye-Exit the program.
Commit-Submit the changes made in offline mode.
Delete-Delete a configuration item from the project list.
Diag-Change to 'netsh diag'Context.
Dump-Displays a configuration script.
Exec-Run a script file.
Exit-Exit the program.
Firewall-Change to 'netsh Firewall'Context.
Help-Displays the command list.
Interface-Change to 'netsh interface'Context.
Offline-Set the current mode to offline.
Online-Set the current mode to a VM instance.
Popd-Open a context from the stack.
Pushd-Push the current context into the stack.
Quit-Exit the program.
Ras-Change to 'netsh Ras'Context.
Routing-Change to 'netsh routing'Context.
Set-Update Configuration Settings.
Show-Display Information
Unalias-Delete an alias.
Winsock-Change to 'netsh winsock'Context.

The following sub-contexts are available:
Bridge diag firewall interface Ras routing Winsock

If you need more help information, enter the command,
Followed?.

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.