Netsh command to configure network DNS, IP, Gateway
Source: Internet
Author: User
1. C :\> netsh interface ip add address \ "inet \" 192.168.0.20 255.255.255.0 # inet is my local connection name
2. C :\> netsh interface ip add address \ "inet \" gateway = 192.168.0.1 gwmetric = 2 # gwmetric is the number of hops added
3. C :\> netsh interface ip add dns \ "inet \" 202.106.0.20 #202.106.0.20 is the DNS address of Beijing
C :\> netsh interface ip add dns \ "inet \" 202.106.196.115 index = 2
1. Add an IP address and a default gateway (yes. For details about how to reset or update the original IP address, refer to the third point)
Netsh interface ip add address
Usage: add address [name =] [[addr =] IP address [mask =] IP subnet mask]
[[Gateway =] IP address [gwmetric =] integer]
Parameters:
Name-IP interface name.
Addr-IP address to be added to this interface.
Mask-specifies the IP address subnet mask.
Gateway-the default gateway of the specified IP address.
Gwmetric-the number of hops of the default gateway.
Note: Add IP addresses and
Default Gateway.
Example:
Add address \ "Local Area Connection \" 10.0.0.2 255.0.0.0
Add address \ "Local Area Connection \" Gateway = 10.0.0.3 gwmetric = 2
The first command adds a static IP address 10.0.0.2 to the local connection interface, subnet mask
It is 255.0.0.0. The second command adds an IP address to the interface with 2 hops.
10.0.0.3 is the second default gateway.
My instances:
(1) netsh interface IP add address \ "localconnection \" 172.20.0.49 255.255.252.0
This command sets the IP address of localconnection to 172.20.0.49, And the subnet mask to 255.255.252.0.
(2)
C: \\> netsh interface IP add address \ "localconnection \" Gateway = 172.20.0.254 gwmetric = 1
This command sets the default gateway of localconnection to 172.20.0.254, and the default gateway has 1 hop.
2. Add DNS
Netsh interface IP add DNS?
Usage: Add DNS [name =] [ADDR =] [[Index =] integer]
Parameters:
Mark Value
Name-name of the DNS server interface.
ADDR-IP address of the added DNS server.
Index-specifies the DNS server address.
Specify the index (preference ).
Note: Add new DNS Server IP addresses or reindex the list of existing DNS server addresses to modify DNS server preferences.
For example:
Add dns \ "Local Area Connection \" 10.0.0.1
Add dns \ "Local Area Connection \" 10.0.0.3 index = 2
My instances:
Netsh interface ip add dns \ "LocalConnection \" 172.20.0.1
Netsh interface ip add dns \ "LocalConnection \" 202.96.128.68 index = 2
3. Set the IP address, default gateway, and DNS:
Netsh interface IP set address local static 172.20.0.49 255.255.252.0 set IP address and subnet mask
Netsh interface IP set address local static gateway = 172.20.0.254 gwmetric = 1
(Set address name = \ "LocalConnection \" source = dhcp indicates that the IP address is obtained from the dhcp server)
Netsh interface IP set dns \ "LocalConnection \" static 172.20.0.1
(Set dns name = \ "LocalConnection \" source = dhcp)
Iv. Comprehensive examples
Netsh interface IP set address local static 172.20.0.49 255.255.252.0
Netsh interface IP set address local static gateway = 172.20.0.254 gwmetric = 1
Netsh interface IP set dns \ "LocalConnection \" static 172.20.0.1
Netsh interface ip add dns \ "LocalConnection \" 202.96.128.68 index = 2
The above commands are processed in batches:
Edit setIP. bat
Netsh interface IP set address local static % 2 255.255.252.0
Netsh interface IP set address local static gateway = 172.20.0.254 gwmetric = 1
Netsh interface IP set dns \ "% 1 \" static 172.20.0.1
Netsh interface ip add dns \ "% 1 \" 202.96.128.68 index = 2
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.