管理技巧:使用netsh.exe配置TCP/IP

来源:互联网 发布:淘宝达人手机发帖 编辑:程序博客网 时间:2024/06/18 18:45
先,它可以显示你TCP/IP协议的相关设置。在命令提示窗口(CMD.EXE)里输入下列命令:
  netsh interface ip show config

  你还可以用它来更改计算机的IP地址或者配置TCP/IP的其它相关属性。例如,你想为计算机的“本地连接”指定一个静态的IP地址:192.168.0.100,设置其子网掩码为255.255.255.0,并指定默认网关为192.168.0.1,你只需要在命令提示窗口里输入下列命令就可以了:
netsh interface ip set address name="Local Area Connection" static 192.168.0.100 255.255.255.0 192.168.0.1 1
(注意:这是一条完整的命令,输入的时候请不要换行。)

  如果你有一台笔记本电脑,而且你需要在两个以上不同的地方接入网络(并且每个网络都需要使用静态IP地址),那么你也可以使用netsh.exe来快速地切换TCP/IP设置,以适应不同网络的需要。ntesh.exe可以把不同的TCP/IP设置导出成不同的配置文件,然后在需要的时候导入配置文件来更改相应的设置。

  例如,现在你的笔记本接入了网络1,并且已经做好了相应的网络设置。这时你可以在命令提示窗口输入:
  netsh -c interface dump > c:/location1.txt

  通过这条命令把相应的TCP/IP设置导出至c:/下文件名为location1.txt的文本文件。以此类推,你可以把不同网络环境的设置导出到不同的配置文件中。在需要接入不同的网络中时,你只需要使用下面这条命令就可以了:
  netsh -f c:/location1.txt(或者:netsh -f c:/location2.txt

  除此之外,你还可以通过netsh.exe来配置网络适配器,让它从DHCP服务器自动获得IP地址。命令如下:
  netsh interface ip set address "Local Area Connection" dhcp

  还可以进行WINS配置:
  netsh interface ip set wins "Local Area Connection" static 192.168.0.200

  当然,只要你想,你还可以通过netsh.exe使网络适配器动态获得DNS设置:
  netsh interface ip set dns "Local Area Connection" dhcp

  现在你知道了吧,netsh.exe是一个很有用的自定义TCP/IP设置的工具。

The Netsh command is a powerful command-line tool for Windows Server 2003, Windows XP, and Windows 2000. Netsh is available in the Microsoft Windows 2000 Server Resource Kit and is standard in Windows 2003 and XP. Netsh lets you change almost any network configuration setting as well as document network configurations. You can use the command in a batch file or from its own command shell. Netsh has a useful Help system that you can access by adding /? to almost any of its subcommands. Here are 10 cool things that you can use Netsh to do.

10. Show TCP/IP settings—The command

netsh interface ip show config

shows the system's current TCP/IP configuration settings. You can see whether the system is using DHCP or static addressing as well as view the system's current IP address, subnet mask, gateway address, and DNS servers.

9. Change network configuration—Netsh can change the current network configuration. The command

netsh interface ip set  address "Local Area   Connection" static   192.168.0.10 255.255.255.0  192.168.0.254

sets the IP address of the system configuration Local Area Connection to 192.168.0.10, the subnet mask to 255.255.255.0, and the gateway address to 192.168.0.254. This use of Netsh comes in handy for laptops that must switch between static and dynamic addressed networks.

8. Use a dynamic DHCP assigned address—The command

netsh interface ip set  address "Local Area   Connection" dhcp

sets the IP address of the Local Area Connection system configuration to use DHCP addressing.

7. Change a DNS server address—When you change the system's IP address type, you almost always have to change the DNS server's address as well. The command

netsh interface ip set dns  "Local Area Connection"   static 192.168.0.2

configures the Local Area Connection to use a DNS server whose address is 192.168.0.2.

6. Dynamically assign the DNS server address—When you switch to dynamic DHCP addressing, you typically also want the DNS server address to be assigned dynamically. The command

netsh interface ip set dns "Local Area Connection" dhcp

sets the Local Area Connection interface to use a DHCP-assigned DNS address.

5.Configure a WINS server—Netsh also lets you configure WINS servers. The following command configures a system's Local Area Connection interface to use a WINS server that has the IP address 192.168.100.3.

netsh interface ip set wins   "Local Area Connection"   static 192.168.100.3

4. Work with other interfaces—Netsh works with DHCP, Internet Authentication Service (IAS), and RAS interfaces as well as the local network interface. The command

netsh dhcp dump > dhcpcfg.dat

dumps the local DHCP server's configuration to the dhcpcfg.dat file. You can use this file in conjunction with Netsh to recreate the DHCP server.

3. Work with remote systems—One of Netsh's best hidden features is its ability to work with remote systems. The command

netsh set machine remotecomputer

sets the current computer to a different system on the network.

2. Save the current configuration—The Interface Dump subcommand saves your current network configuration and generates a script that you can use to regenerate the configuration. The command

netsh interface dump >   mycfg.dat

redirects the Dump command to the mycfg.dat file.

1. Restore network configuration—The Netsh Exec command runs a Netsh script file. The command

netsh exec mycfg.dat

restores to your system the network configuration data that the preceding sample command saved.


In order to add multiple DNS servers, use the following syntax: add dns "Local Area Connection" 10.0.0.1 add dns "Local Area Connection" 10.0.0.3 index=2 index=2 adds the IP as a secondary dns server.

The commands in the article need to be corrected as follows: 10. netsh interface ip show config 09. Netsh interface ip set address name=”Local Area Connection” source=static addr=192.168.0.10 mask=255.255.255.0 gateway=192.168.0.1 gwmetric=1 08. Netsh interface ip set address name=”Local Area Connection” source=dhcp 07. Netsh interface ip set dns name=”Local Area Connection” source=static addr=192.168.0.2 register=none 06. netsh interface ip set dns name="Local Area Connection" source=dhcp 05. Netsh interface ip set wins name=”Local Area Connection” source=static addr=192.168.100.3 To configure WINS from DHCP: Netsh interface ip set wins name=”Local Area Connection” source=dhcp 04. netsh dump dhcp > dhcpcfg.dat 03. OK 02. netsh dump interface > mycfg.dat 01. OK

To add multiple DNS entries you need to type: netsh interface ip set dns name="Wireless Network Connection" source=static addr=192.168.1.200 register=PRIMARY netsh interface ip add dns name="Wireless Network Connection" addr=192.168.1.5 index=2 Just for fun I tried to just add the Secondary DNS (index=2) without first having a Primary and netsh put the IP address in the primary position. I guess you need to have a Primary DNS entered before you can add Secondary and Tertiary DNS entries.

rldutch1 -November 21, 2004


Find your interface name & set multiple dns entries like this: C:/WINNT/system32>netsh netsh>interface interface>show interface Admin State State Type Interface Name ------------------------------------------------------------------------- Enabled Dedicated Local Area Connection Enabled Internal Internal Enabled Loopback Loopback (Note: Look for "Dedicated" connection types with any name other than a GUID) interface>ip interface ip>delete dns "Local Area Connection" all interface ip>set dns "Local Area Connection" static 10.10.10.2 interface ip>add dns "Local Area Connection" 10.10.10.3 index=2

This works great for Win2k Pro. I put this in a batch file and run it together. Set IP address subnet gateway Set DNS Primary Set DNS Secondary netsh interface ip set address "Local Area Connection" static 10.1.1.15 255.255.255.0 10.1.1.1 1 netsh interface ip set dns "Local Area Connection" static 172.16.0.5 primary netsh interface ip add dns name="Local Area Connection" addr=172.16.0.15 index=2

This is how to Disable and enable an interface using Netsh netsh int set interface name="Local Area Connection 3" admin=disabled netsh int set interface name="Local Area Connection 3" admin=enabled This

Anonymous User -April 30, 2005

原创粉丝点击