To modify the IP, gateway, DNS of Windows by using the command line Netsh

Source: Internet
Author: User

Type network configuration. netsh
# ----------------------------------
# interface IP Configuration
# ----------------------------------
pushd Interface IP
#
# interface IP configuration for "Local Area Connection"
#设静态IP
Set address name= "Local Area Connection" Source=static addr=192.168.1.20 mask=255.255.255.0
#设默认网关
Set address name= "Local Area Connection" gateway=192.168.1.1 gwmetric=0
#设首选dns
Set DNS name= "Local Area Connection" Source=static addr=192.168.1.1 register=primary
#设备用dns
Add DNS name= "Local Area Connection" addr=211.90.88.129 index=2
Set wins name= "Local Area Connection" Source=static Addr=none
#
#显示 "Local Area Connection" configuration results
Show config Local Area Connection
#
# interface IP configuration for "Local Area Connection"
#设自动获取ip
Set address name= "Local Area Connection" Source=dhcp
#设自动获取dns
Set DNS name= "Local Area Connection" Source=dhcp register=primary
Set wins name= "Local Area Connection" Source=dhcp
#
#显示 "Local Area Connection" configuration results
Show config Local Area Connection
popd
# interface IP Configuration End


netsh exec network configuration. netsh

Interface "Local Area Connection" configuration
DHCP Enable No
IP Address 192.168.1.20
Subnet Mask 255.255.255.0
Default gateway: 192.168.1.1
gatewaymetric:0
InterfaceMetric 0
Statically configured DNS servers: 192.168.1.1
211.90.88.129
Statically configured WINS servers: none
Which prefix to register with: just the main

DHCP is already enabled on this interface.

Interface "Local Area Connection" configuration
DHCP enabled is
InterfaceMetric 0
DHCP-configured DNS servers: 221.228.255.1
218.2.135.1
DHCP-configured WINS servers: none
Which prefix to register with: just the main

More complex settings, to be implemented using the command line, can be set up to be saved as a configuration file:
netsh interface dump> network configuration. netsh
Modify the network configuration. netsh file to retain, modify the pushd and POPD sections that are required, and the lines needed in the paragraph
Later, modify the configuration as needed:
netsh exec network configuration. netsh
Or
netsh < network configuration. netsh


You can also write a bat file:
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

Related Article

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.