Comments
Item

Configure IP Address and DNS from Command Line

The IP address of your computer can be set from the command prompt by running the following commands at an administrative level prompt:

netsh interface ip set address name="Local Area Connection" static 123.123.123.123 255.255.255.0 123.123.123.1 1

Local Area Connection is the name of the adapter you want to modify. In single NIC systems it is normally called Local Area Connection.

123.123.123.123 is the IP address you want to set. 

255.255.255.0 is the subnet mask.

123.123.123.1 is the gateway.

1 is the gateway metric. You can leave this as 1 for almost all cases. 

If you want to enable DHCP you can run:

netsh interface ip set address name="Local Area Connection" dhcp

There are two commands for DNS since administrators typically configure a primary and secondary DNS server. 

For the primary DNS run:

netsh interface ip set dns name="Local Area Connection" static 208.67.222.222

For the secondary run:

netsh interface ip add dns name="Local Area Connection" 208.67.220.220 index=2

If you want to configure the computer to use DNS from DHCP run:

netsh interface ip set dnsservers name="Local Area Connection" source=dhcp

When you are finished with all of your IP and DNS changes run ipconfig -all to review the new settings.

 
Free Computer Magazines and eBooks
 
Comments
Philip Knudsen
2 years ago
Nice!
I used it, but it didn´t work due to one missing parameter "gwmetric", set it to 1. You should add a one at the end of this line, since you added the default gateway:

netsh interface ip set address name="Local Area Connection" static 123.123.123.123 255.255.255.0 123.123.123.1 1

I also created some bat-files to store the commands in, that way I can quickly change from dhcp to static, dependeing on what network I am working in.
Steve Sinchak
2 years ago
Thanks Philip for catching my mistake, I updated the article. For some reason on Windows 7 when you leave the gateway metric blank it assigns a default value but on other operating systems it has issues. What OS did you see the error on?
Philip Knudsen
2 years ago
I used XP-professional SP3.
antony
2 years ago
i just did the step for dsn and the ipconfig !!!this is the funny part how i go back to the setting the pc have before?sorry have a nice and happy new year
Jared
2 years ago
Tip #1 - create a shortcut to cmd.exe (Windows\system32\cmd.exe) in same dir, set the shortcut to start as admin
Tip #2 - rename your "local area connection" to "eth0" (or respective number) to save yourself some time.
Tip #3 - netsh>dump and netsh>exec to quickly change back and forth configurations
loretta bowen
2 years ago
i need help on finding out how to move my background screen to right it is to far to left and i have tryed the mouse and arrows and it will not move it is black for about1/4 inch to the right background and icons to far to left
Vik
One year ago
Super!!