Use the netsh command to modify the IP address, gateway, and DNS of windows.

Source: Internet
Author: User

Many people ask me how to use commands to modify the IP address of a Windows system. This method saves time and effort for system testers who often need to change IP addresses. I think not only do my friends and I need to solve this problem, but many netizens also need to solve it. I will discuss and share with you here.

The 'netsh' command is required to change the IP address, gateway, and DNS in windows. You can search for the netsh command on the Internet to find out the function. netsh is a command line script utility that allows you to display or modify the network configuration of the currently running computer locally or remotely. Netsh also provides a script function that allows you to run a group of commands in batch mode on a specified computer. To archive or configure other servers, netsh can also save the configuration script in a text file. From this we can see that netsh is a very powerful command, and experienced administrators and engineers will not doubt its capabilities. Today, I will not discuss all the functions of the netsh command in this article. I will only introduce some common and basic netsh usage methods.

Method 1: manually set the IP address, gateway, and DNS of windows.

Step 1: Click Start> Run, Enter cmd, and press Enter;

Step 2: Enter "netsh interface IP" at the DOS interface command prompt to enter the configuration mode;

Step 3: enter SET address "Nic name" static IP mask gateway hops.

(For example, set address "Local Connection" static 192.168.0.1 255.255.255.0 192.168.0.254 1) this step is the IP address, subnet mask, and gateway of the NIC;

Step 4: Enter netsh interface IP Set DNS "Nic name" static primary DNS

Netsh interface IP Set DNS "Nic name" static secondary DNS No.

For example:
Netsh interface IP Set DNS "Local Connection" static 202.194.40.1
Netsh interface IP add DNS "Local Connection" 202.194.40.2 2
Note: If you do not need secondary DNS, you do not need to write the second line, just write the same as the primary DNS.

Now, we have manually set all the basic parameters for the Windows Nic.

Method 2: Set the Windows system IP address, gateway, and DNS for batch processing.

Step 1: Create a TXT notepad;

Step 2: copy the following content to the new notepad and fill in relevant parameters according to your actual needs. Refer to the first method.

@ Echo off

Netsh interface IP Set address "Nic name" static IP mask gateway hops

Netsh interface IP Set DNS "Nic name" static primary DNS

Netsh interface IP Set DNS "Nic name" static secondary DNS number (note that you can remove this line if you do not need secondary DNS)

Step 3: copy the above content to notepad and modify the relevant parameters and save it as a. BAT file. In this way, when you need to change the IP address, you only need to double-click to execute the. bat batch file to complete the NIC-related parameter settings. Does it look more convenient than the first method!

The above describes how to change the NIC of the local machine to a fixed parameter. If you want to change the NIC of the Local Machine to DHCP to automatically obtain the IP address, how can you set it? Let me give you a brief introduction.

Step 1: Click Start> Run, Enter cmd, and press Enter;

Step 2: Enter "netsh interface IP" at the DOS interface command prompt to enter the configuration mode;

Step 3: Enter netsh interface IP Set address "Local Connection" DHCP

Netsh interface IP Set DNS "Local Connection" DHCP

For example:
Netsh interface IP Set address "Local Connection" DHCP
Netsh interface IP Set DNS "Local Connection" DHCP
After the two commands are completed, you can change the NIC status of the local machine to DHCP to automatically obtain the IP address. Of course, you can also refer to the second method of setting static IP to create a batch file, which is more convenient! @ Echo off must be added to the first line of the file during batch processing.

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.