Use netsh to modify windows IP addresses, gateways, and DNS

Source: Internet
Author: User

Type network configuration. netsh
#----------------------------------
# Interface IP configuration
#----------------------------------
Pushd interface IP
#
# "Local Connection" interface IP configuration
# Static IP
Set address name = "Local Connection" Source = static ADDR = 192.168.1.20 mask = 255.255.255.0
# Set the Default Gateway
Set address name = "Local Connection" Gateway = 192.168.1.1 gwmetric = 0
# Set preferred DNS
Set DNS name = "Local Connection" Source = static ADDR = 192.168.1.1 register = primary
# Device DNS
Add DNS name = "Local Connection" ADDR = 211.90.88.129 Index = 2
Set wins name = "Local Connection" Source = static ADDR = none
#
# Display the "local connection" configuration result
Show config local connection
#
# "Local Connection" interface IP configuration
# Set automatic IP address acquisition
Set address name = "Local Connection" Source = DHCP
# Set automatic DNS Retrieval
Set DNS name = "Local Connection" Source = DHCP register = primary
Set wins name = "Local Connection" Source = DHCP
#
# Display the "local connection" configuration result
Show config local connection
Popd
# End of interface IP configuration

Netsh exec network configuration. netsh

Interface "Local Connection" configuration
DHCP enabled or not
IP address 192.168.1.20
Subnet Mask 255.255.255.0
Default Gateway: 192.168.1.1
Gatewaymetric: 0
Interfacemetric 0
Static DNS server: 192.168.1.1
211.90.88.129
Static WINS server: None
Which prefix is used for registration?

DHCP has been enabled on this interface.

Interface "Local Connection" configuration
DHCP enabled is
Interfacemetric 0
DNS server configured through DHCP: 221.228.255.1
218.2.135.1
WINS server configured through DHCP: None
Which prefix is used for registration?

For more complex settings, you can use the command line to set and save the settings as a configuration file:
Netsh interface dump> network configuration. netsh
Modify the "Network Configuration. netsh" file, retain and modify the required pushd and popd segments, and the required rows in the segments.
Modify the configuration later as needed:
Netsh exec network configuration. netsh
Or
Netsh <network configuration. netsh

You can also write a BAT file:
Echo # Set static IP
Netsh interface IP Set address name = "Local Connection" Source = static ADDR = 192.168.1.20 mask = 255.255.255.0
Echo # Set the Default Gateway
Netsh interface IP Set address name = "Local Connection" Gateway = 192.168.1.1 gwmetric = 0
Echo # Set preferred DNS
Netsh interface IP Set DNS name = "Local Connection" Source = static ADDR = 192.168.1.1 register = primary
Echo # device DNS
Netsh interface IP add DNS name = "Local Connection" ADDR = 211.90.88.129 Index = 2
Netsh interface IP Set wins name = "Local Connection" Source = static ADDR = none
Echo #
Echo # display the "local connection" configuration result
Netsh interface IP show config local connection
Echo #
Echo # interface IP Address Configuration for "Local Connection"
Echo # set to automatically obtain the IP address
Netsh interface IP Set address name = "Local Connection" Source = DHCP
Echo # Set automatic DNS Retrieval
Netsh interface IP Set DNS name = "Local Connection" Source = DHCP register = primary
Echo netsh interface IP Set wins name = "Local Connection" Source = DHCP

Echo # display the "local connection" configuration result
Netsh interface IP show config local connection
Echo # End of interface IP configuration

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.