Search A-Z index Help
University of Cambridge Home Physics Dept Home Mike Roses' Home Page TCM Group Home

Using netsh.exe to change your windows network configuration by command

Windows 2000

If you need to plug your laptop into different networks, you can save and restore the appropriate network configuration using the netsh.exe utility which ships with W2K and XP. When you have your laptop correctly configured for your office network, you can save the network configuration for later restoration. Note you will need to do this as user with administrative privelege - hopefully not your normal userID as you should not be making general use of a win OS as a user with admin rights.

netsh -c interface dump > c:\configs\officeinterface.txt

Now lets say you take it home and reconfigure it correctly for you home network. To save you home network configuration for later use:

netsh -c interface dump > c:\configs\homeinterface.txt

OK. Now you take the laptop back to the office and you need to reconfigure for the office environment
Use the following command to restore your office network interface:

netsh -f c:\configs\officeinterface.txt

At end of day, you take it home. To setup for home, run:

netsh -f c:\configs\homeinterface.txt Shamelessly lifted from Wayne Maples' web page

Windows XP, particularly Home as it does not have the Alternate Configuration stuff

You use the program NETSH.EXE, which is normally in the directory c:\windows\system32. You must be logged on with administrator rights to use it, or use "Run as..." on the right mouse button to run it as an administrator.

NETSH.EXE requires a library called framedyn.dll that's in the c:\windows\system32\wbem directory. If it is not on your path then add it (My Computer -> Properties -> Advanced -> Environment).

Set up your networking using the usual method with Settings|Network Connections|some adapter| TCP/IP|Properties, then open a command window (as an administrator), and run

netsh interface dump > c:\directory\network_config.txt

Now edit the config.txt file. NETSH has a bug, and creates a file which it cannot read. The problem is that it will put "register=PRIMARY"; on the lines defining your DNS servers, e.g.

    set dns name="Local Area Connection" source=static addr=129.100.2.12 register=PRIMARY

    add dns name="Local Area Connection" addr=129.100.2.51 register=PRIMARY
Delete this, so the lines look like this:
    set dns name="Local Area Connection" source=static addr=129.100.2.12

    add dns name="Local Area Connection" addr=129.100.2.51

To run the script use this command (as administrator):

c:\windows\system32\netsh -f c:\directory\network_config.txt

You can create a desktop shortcut that uses this command if you wish. You can setup your machine for a different location and dump/saving the configuration in a different file each time, then create the commands that will restore/load the network config.

Shamelessly lifted from Duncan Murdochs' web page