Configuring static IP and DHCP on Windows

This article will cover a quick method to configure network connection under Windows.

Let's say you have a lap-top computer that you use in two different places. The first one is with static IP address with following paramethers:

IP: 192.168.20.10
Network mask: 255.255.255.0
Gateway: 192.168.10.3
DNS: 192.168.10.2
WINS: 192.168.10.4

Static IP configuration

In the other place you use DHCP.

Dynamic IP (DHCP)

When you need to switch from statis IP to DHCP you just toggle a radio button. But the opposite action takes a lot of time enterin IP address, mask and so on. This article will help you to save this typing.

The netsh application

Netsh is an useful conzole application for managing network interfaces. It has a plenty of capabilities, but we'll limit to some of them. Full description can be found on http://support.microsoft.com/?kbid=242468.

We'll use .bat files to list both configuration. You can read more on these files on http://en.wikipedia.org/wiki/Batch_file.

You have to know the name of the interface that you'll setup. This can be done from Start -> Control panel -> Network connections (see picture). In our case this will be "Local Area Connection". If you computer has more than one LAN cads (network interfaces), check witch is the one where you plug the cable in. If you want to ajust you wireless connection then in the picture this is "Wireless Network Connection".

Network connections

Static IP address

To ajust a static IP address, create the file static.bat containing:

netsh interface ip set address name="Local Area Connection" static 192.168.20.10 255.255.255.0 192.168.2.3 1
netsh interface ip set dns "Local Area Connection" static 192.168.20.2
netsh interface ip set wins "Local Area Connection" static 192.168.20.4

First command sets IP 192.168.20.10 with subnet mask 255.255.255.0 and gateway 192.168.2.3. Second command setups DNS server address, and third - WINS server address.

Dynamic IP address (DHCP)

Create file dhcp.bat:

netsh interface ip set address "Local Area Connection" dhcp
netsh interface ip set dns "Local Area Connection" dhcp

If you DNS is not set up automatically, content of the file should be:

netsh interface ip set address "Local Area Connection" dhcp
netsh interface ip set dns "Local Area Connection" static 192.168.30.2

where 192.168.30.2 is the IP address of DNS server.

And final touches

Create above files in My documents folder. Put shortcuts on your desktop to both of them. Now instead of changing network setup manually, just double-click on of the files.

 

Post a comment (fixed now)

Comments:

Galin Stoyanov (12-07-2009 23:54) :
It helps alot. Thank you. But will this work with WiFi and should I replace "Local Area Connection" with "Wireless Network Connection" only to make it work?

Back to articles list

This page was last modified on 2014-10-02 05:17:36