本文共 3237 字,大约阅读时间需要 10 分钟。
If you have ever added multiple IP addresses to a single Windows server, going through the graphical interface is an incredible pain as each IP must be added manually, each in a new dialog box. Here’s a simple solution.
如果您曾经将多个IP地址添加到单个Windows服务器,则通过图形界面非常麻烦,因为每个IP必须手动添加,每个IP地址都在一个新对话框中。 这是一个简单的解决方案。
Needless to say, this can be incredibly monotonous and time consuming if you are adding more than a few IP addresses. Thankfully, there is a much easier way which allows you to add an entire subnet (or more) in seconds.
不用说,如果要添加多个IP地址,这可能会非常单调且耗时。 值得庆幸的是,有一种更简单的方法可以让您在几秒钟内添加整个子网(或更多)。
Windows includes the “netsh” command which allows you to configure just about any aspect of your network connections. If you view the accepted parameters using “netsh /?” you will be presented with a list of commands each which have their own list of commands (and so on). For the purpose of adding IP addresses, we are interested in this string of parameters:
Windows包含“ netsh”命令,该命令使您几乎可以配置网络连接的任何方面。 如果使用“ netsh /?”查看接受的参数您将看到一个命令列表,每个命令都有自己的命令列表(依此类推)。 为了添加IP地址,我们对以下参数字符串感兴趣:
netsh interface ipv4 add address
netsh接口ipv4添加地址
Note: For Windows Server 2003/XP and earlier, “ipv4” should be replaced with just “ip” in the netsh command.
注意:对于Windows Server 2003 / XP和更早版本,在netsh命令中应仅将“ ipv4”替换为“ ip”。
If you view the help information, you can see the full list of accepted parameters but for the most part what you will be interested in is something like this:
如果查看帮助信息,则可以看到已接受参数的完整列表,但是在大多数情况下,您会感兴趣的是:
netsh interface ipv4 add address “Local Area Connection” 192.168.1.2 255.255.255.0
netsh接口ipv4添加地址“本地连接” 192.168.1.2 255.255.255.0
The above command adds the IP Address 192.168.1.2 (with Subnet Mask 255.255.255.0) to the connection titled “Local Area Network”.
上面的命令将IP地址192.168.1.2(带有子网掩码255.255.255.0)添加到名为“局域网”的连接中。
When we accompany a netsh command with the FOR /L loop, we can quickly add multiple IP addresses. The syntax for the FOR /L loop looks like this:
当netsh命令与FOR / L循环一起使用时,我们可以快速添加多个IP地址。 FOR / L循环的语法如下所示:
FOR /L %variable IN (start,step,end) DO command
FOR / L%variable IN(开始,步骤,结束)DO命令
So we could easily add every IP address from an entire subnet using this command:
因此,我们可以使用以下命令轻松地从整个子网中添加每个IP地址:
FOR /L %A IN (0,1,255) DO netsh interface ipv4 add address “Local Area Connection” 192.168.1.%A 255.255.255.0
FOR / L%A IN(0,1,255)做netsh接口ipv4添加地址“本地连接” 192.168.1。%A 255.255.255.0
This command takes about 20 seconds to run, where adding the same number of IP addresses manually would take significantly longer.
该命令运行大约需要20秒钟,而手动添加相同数量的IP地址将花费更长的时间。
Here is the initial configuration on our network adapter:
这是我们的网络适配器上的初始配置:
ipconfig /all
ipconfig /全部
Now run netsh from within a FOR /L loop to add IP’s 192.168.1.10-20 to this adapter:
现在从FOR / L循环中运行netsh,将IP的192.168.1.10-20添加到此适配器:
FOR /L %A IN (10,1,20) DO netsh interface ipv4 add address “Local Area Connection” 192.168.1.%A 255.255.255.0
FOR / L%A IN(10,1,20)DO netsh接口ipv4添加地址“本地连接” 192.168.1。%A 255.255.255.0
After the above command is run, viewing the IP Configuration of the adapter now shows:
运行以上命令后,现在查看适配器的IP配置将显示:
翻译自:
转载地址:http://ozxwd.baihongyu.com/