Quickly change IP configuration with netsh
Issue
Sometimes it happens that your status is not systematically set as DHCP client, depending on the environment in which it operates. It becomes cumbersome to constantly change the TCP/IP parameters. Consider a simple example:
- Environment 1: Office. The parameters are:
- IP Address: 10.21.45.87 / 16
- Gateway: 10.21.47.100
- DNS: 10.21.48.127
- WINS: 10.21.48.128
- Environment 2: Main Client at which it moves 2 to 3 times per week.
- IP Address: 192.168.27.101 / 24
- Gateway: 192.168.27.100
- DNS: 192.168.27.100
- Environment 3: Home: DHCP client
We can note that changing environment is not a easy task. Fortunately, there is a feature of Windows that will simplify our task.
Solution
As you already know netsh allow you to change most TCP/IP parameters via command line.
So we will simply configure for the environments that a mostly used.
- Start with the "office" environment in the example above. We will of course enter the settings, step by step. When the NIC is configured, open a command prompt and simply type :
netsh -c interface dump >office.txt
This is the first step,you just create a netsh configuration file.
- For the client configuration, the procedure is the same:
- configure the network card with the correct parameters
- open a command prompt
netsh -c interface dump >client.txt
- And finally, the home setup:
- configure the DHCP client card
- open a command prompt
taper netsh -c interface dump >home.txt
How to move from one configuration to another? Just call the corresponding configuration file:
- Office:
- open a command prompt
- Client:
- open a command prompt
- type
netsh -f client.txt
- Home:
- open a command prompt
- type
netsh -f home.txt
- The benefits:
- No need to input tedious when changing environment
- If an environment changes, it directly modifies the corresponding txt file.