Change Windows Network Configuration from the Command Line
Do you frequently find yourself switching between different IP addresses in your Windows laptop when plugging onto different networks?
This is quite common for field engineers who need to connect to various customer networks. It is quite frustrating to click a dozen times before you can make a single IP address change.
Instead of changing the network configuration from the network interface GUIs found in Windows, you can change the configuration with the netsh command-line tool instead. Netsh also provides a scripting feature that allows you to run a set of commands in batch mode.
Netsh is included in Microsoft Windows NT line of operating systems beginning with Windows 2000.
Netsh can be used to perform the following tasks:
- Configure interfaces
- Configure routing protocols
- Configure filters
- Configure routes
- Configure remote access behavior for Windows-based remote access routers that are running the Routing and Remote Access Server (RRAS) Service
- Display the configuration of a currently running router on any computer
- Use the scripting feature to run a collection of commands in batch mode against a specified router
Below are some examples on how netsh can be used:
To display the TCP/IP settings for all your network interfaces:
netsh interface ip show config
To change to a static IP address of 192.168.1.1/255.255.255.0 with a default route of 192.168.1.1 for the network interface named ‘Local Area Connection':
netsh interface ip set address name="Local Area Connection" source=static addr=192.168.1.100 mask=255.255.255.0 gateway=192.168.1.1
To configure the network interface for DHCP:
netsh interface ip set address name="Local Area Connection" source=dhcp