Using netsh to configure network from windows command line cmd

Configuring dns and wins servers

Add a preferred DNS server:

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

Add an alternate DNS server:

netsh interface ip add dns "Local Area Connection" 8.8.4.4

Add 3rd DNS server:

netsh interface ip add dns "Local Area Connection" 192.168.1.30 index=3

Setting the automatic retrieval of a preferred and alternate DNS server from a DHCP server:

netsh interface ip set dns "Local Area Connection" dhcp

Installing WINS server:

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

Configuring network parameters (ip-addresses, netmask and gateway)

Setting the ip-address, mask and gateway:

netsh interface ip set address name="Local Area Connection" static 192.168.1.15 255.255.255.0 192.168.1.1

whereLocal Area Connection – the name of your network interface.192.168.1.15 – network address (ip address).255.255.255.0 – network mask.192.168.1.1 – default gateway.

Setting an additional ip-address:

netsh interface ip add address name="Local Area Connection" 192.168.1.20 255.255.255.0

Enable the automatic acquisition of ip-address, netmask and gateway from the DHCP server:

netsh interface ip set address "Local Area Connection" dhcp

Enable and disable network interfaces

Disable network interface:

Netsh command to change from static ip address to dhcp « memorise

To switch the specified adapter from a static address to DHCP, type the following command:
netsh interface ip set address “Local Area Connection” dhcp

NOTE: Typing this command changes the interface named “Local Area Connection” to DHCP.

To display all of the adapters in the computer with their current IP addresses to determine the correct adapter name, type the following command:
Netsh interface ip show config

To change to a static address, type the following command:
netsh interface ip set address “Local Area Connection” static ipaddr subnetmask gateway metric

:/>  How to Fix CHKDSK Cannot Continue in Read Only Mode

NOTE: Replace ipaddr with the static IP address, subnetmask with the subnet mask, gateway with the default gateway and, if necessary, metric with the appropriate metric. The following example changes the interface “Local Area Connection” to a static address of 192.168.0.10 with a subnet mask of 255.255.255.0, and the interface has a default gateway of 192.168.0.1 with a metric of 1:

netsh interface ip set address “Local Area Connection” static 192.168.0.10 255.255.255.0 192.168.0.1 1

With Netsh.exe you can easily view your TCP/IP settings. Type the following command in a Command Prompt window (CMD.EXE):

netsh interface ip show config

With Netsh.exe, you can easily configure your computer’s IP address and other TCP/IP related settings. For example:

The following command configures the interface named Local Area Connection with the static IP address 192.168.0.100, the subnet mask of 255.255.255.0, and a default gateway of 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

(The above line is one long line, copy paste it as one line)

Netsh.exe can be also useful in certain scenarios such as when you have a portable computer that needs to be relocated between 2 or more office locations, while still maintaining a specific and static IP address configuration. With Netsh.exe, you can easily save and restore the appropriate network configuration.

Automating Service Template Deployments in SCVMM 2022

First, connect your portable computer to location #1, and then manually configure the required settings (such as the IP address, Subnet Mask, Default Gateway, DNS and WINS addresses).

Now, you need to export your current IP settings to a text file. Use the following command:

netsh -c interface dump > c:location1.txt

When you reach location #2, do the same thing, only keep the new settings to a different file:

netsh -c interface dump > c:location2.txt

You can go on with any other location you may need, but we’ll keep it simple and only use 2 examples.

:/>  DPC Latency Checker 1.3 Download (Free) - dpclat.exe

Now, whenever you need to quickly import your IP settings and change them between location #1 and location #2, just enter the following command in a Command Prompt window (CMD.EXE):

netsh -f c:location1.txt

or

netsh -f c:location2.txt

and so on.

You can also use the global EXEC switch instead of -F:

netsh exec c:location2.txt

Netsh.exe can also be used to configure your NIC to automatically obtain an IP address from a DHCP server:

netsh interface ip set address "Local Area Connection" dhcp

Would you like to configure DNS and WINS addresses from the Command Prompt? You can. See this example for DNS:

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

and this one for WINS:

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

Or, if you want, you can configure your NIC to dynamically obtain it’s DNS settings:

netsh interface ip set dns "Local Area Connection" dhcp

BTW, if you want to set a primary and secondary DNS address, add index=1 and index=2 respectively to the lines of Netsh command.

As you now see, Netsh.exe has many features you might find useful, and that goes beyond saying even without looking into the other valuable options that exist in the command.

Save and restore network interface configurations

Well, now the fun part. Let’s talk about how to save the network settings as a configuration file and restore from the configuration file. This can be useful to those who are constantly changing network settings.

Save network settings as a file:

C:WindowsSystem32>netsh -c interface dump > C:my-config.txt

Restore network settings from file from configuration:

C:WindowsSystem32>netsh -f C:my-config.txt

That’s all. We have considered far from all the features of the Netsh.exe utility, but only the most frequently used ones. Comment, subscribe. Bye everyone.

:/>  Как восстановить Windows 7 через командную строку | IT блоги - Windows, *nix, vmWare, Hyper-V, NetApp, SEO, HTML, видеонаблюдение

View network settings

Advanced network interface configuration output:

netsh interface ip show config

View interface status (connected/disconnected):

C:WindowsSystem32>netsh interface ip show interface
Инд  Мет         MTU         Состояние     Имя
---  ----------  ----------  ------------  ---------------------------
  1          50  4294967295  connected     Loopback Pseudo-Interface 1
 12          10        1300  disconnected  Local Area Connection

View the routing table:

netsh interface ip show route

View IP addresses configuration:

netsh interface ip show addresses

View DNS server addresses:

netsh interface ip show dnsservers

Просмотр адресов WINS-сервера:

netsh interface ip show winsservers

What is netsh?

Netsh is a command-line scripting utility that allows you to, either locally or remotely, display or modify the network configuration of a computer that is currently running. Netsh also provides a scripting feature that allows you to run a group of commands in batch mode against a specified computer. Netsh can also save a configuration script in a text file for archival purposes or to help you configure other servers.

Оставьте комментарий

Adblock
detector