Ask your question Report

How to change IP address from command prompt [Solved/Closed]

nareen123 11Posts April 15, 2008Registration date - Last answer on Apr 29, 2011 6:45pm BST
Hello,
Is there any way to change IP address of computer from Command prompt?
I use WinXP as OS and I would like to know if I can change IP from Command prompt
Please help me out.
Read more 

How to change IP address from command prompt »

155 replies
Answer
+37
moins plus
Of course you can change the IP from the command prompt.

The command is:
to change IP and default gateway:
netsh int ip set address "local area connection" static 192.168.0.101 255.255.255.0 192.168.0.254 1

to change DNS:
netsh int ip set dns "local area connection" static 192.168.0.254 primary

This is assuming 3 things.
1) The network adapter you're trying to change the IP for is "local area connection". It could also be "local area connection 2" or "wireless network connection". Look in your control panel for the correct name
2) The IP you want to set is 192.168.0.101, change this to whatever IP to want to use.
3) The default gateway and dns are the same IP. If you are using some kind of router they usually are. Change this to match your network config found with the command ipconfig /all

You will need to run both commands to change the IP.

experto - Dec 22, 2009 1:12pm GMT
Unfortenately not.
ALA - Jan 6, 2010 3:31am GMT
Great help & teachings on changing IP settings from DOS prompt. Thanks!

So, when you execute these NETSH commands from the command prompt, do they just last for the current session or are they made permanent to the system so are still in effect when you reboot?
savio_scott - Mar 2, 2010 1:36pm GMT
Hi,
I just want to know if the Ip address is assigned by the DHCP server i.e 169.254.x.x
And even if the ip release and ip renew commmand is also not assigning the required ip address of the network i.e 19.168.x.x. Then which command would work to change the DHCP ip address to the required one.
Your reply will be helpful.

Thanks for previous answer
Answer
+10
moins plus
To change to static IP:
----------------------------------------------------------------
This changes the IP address and Default Gateway:
netsh int ip set address "local area connection" static {192.168.0.101} 255.255.255.0 {192.168.0.254} 1

This changes DNS:
netsh int ip set dns "local area connection" static {192.168.0.254} primary
----------------------------------------------------------------
You will want to change the values between the curly braces, but do not use the curly braces when you run the command.
----------------------------------------------------------------
To change the interface back to DHCP (get IP automatically) use this command:
netsh int ip set address "local area connection" dhcp

DNS:
netsh int ip set dns "local area connection" dhcp
----------------------------------------------------------------


============================
I would recommend you view the help for this command, it will shed much more insight on what you're actually doing.
The netsh command allows you to change many things such the firewall configuration to the ip addresses.
You can get help for the netsh command by adding each word of the command and adding /?. For example:

=================================
C:\Documents and Settings\2xod>netsh /?

Usage: netsh [-a AliasFile] [-c Context] [-r RemoteMachine]
[Command | -f ScriptFile]

The following commands are available:

Commands in this context:
? - Displays a list of commands.
add - Adds a configuration entry to a list of entries.
bridge - Changes to the `netsh bridge' context.
delete - Deletes a configuration entry from a list of entries.
diag - Changes to the `netsh diag' context.
dump - Displays a configuration script.
exec - Runs a script file.
firewall - Changes to the `netsh firewall' context.
help - Displays a list of commands.
interface - Changes to the `netsh interface' context.
ras - Changes to the `netsh ras' context.
routing - Changes to the `netsh routing' context.
set - Updates configuration settings.
show - Displays information.
winsock - Changes to the `netsh winsock' context.

The following sub-contexts are available:
bridge diag firewall interface ras routing winsock

To view help for a command, type the command, followed by a space, and then
type ?.

=================================
C:\Documents and Settings\2xod>netsh int /?

The following commands are available:

Commands in this context:
? - Displays a list of commands.
add - Adds a configuration entry to a table.
delete - Deletes a configuration entry from a table.
dump - Displays a configuration script.
help - Displays a list of commands.
ip - Changes to the `netsh interface ip' context.
ipv6 - Changes to the `netsh interface ipv6' context.
portproxy - Changes to the `netsh interface portproxy' context.
reset - Resets information.
set - Sets configuration information.
show - Displays information.

The following sub-contexts are available:
ip ipv6 portproxy

To view help for a command, type the command, followed by a space, and then
type ?.

=================================
C:\Documents and Settings\2xod>netsh int ip /?

The following commands are available:

Commands in this context:
? - Displays a list of commands.
add - Adds a configuration entry to a table.
delete - Deletes a configuration entry from a table.
dump - Displays a configuration script.
help - Displays a list of commands.
reset - Resets TCP/IP and related components to a clean state.
set - Sets configuration information.
show - Displays information.

To view help for a command, type the command, followed by a space, and then type ?.

=================================
C:\Documents and Settings\2xod>netsh int ip set /?

The following commands are available:

Commands in this context:
set address - Sets the IP address or default gateway to the specified interface.
set dns - Sets DNS server mode and addresses.
set wins - Sets WINS server mode and addresses.

=================================
C:\Documents and Settings\2xod>netsh int ip set address /?

Usage: set address [name=]<string>
[[source=]dhcp |
[source=] static [addr=]IP address [mask=]IP subnet mask]
[[gateway=]<IP address>|none [gwmetric=]integer]

Parameters:

Tag Value
name - The name of the interface.
source - One of the following values:
dhcp: Sets DHCP as the source for configuring IP
addresses for the specific interface.
static: Sets the source for configuring IP addresses
to local static configuration.

gateway - One of the following values:
<IP address>: A specific default gateway for the
static IP address you are setting.
none: No default gateways are set.
gwmetric - The metric for the default gateway. This field should
not be set if gateway is set to 'none'.
The following options are used only if source is 'static':

addr - An IP address for the specified interface.
mask - The subnet mask for the specified IP address.

Remarks: Used to change the IP address configuration mode from either DHCP to
static mode or static mode to DHCP. Adds IP addresses on an
interface with static IP address or adds default gateways.

Examples:

set address name="Local Area Connection" source=dhcp
set address local static 10.0.0.9 255.0.0.0 10.0.0.1 1


C:\Documents and Settings\2xod>
=================================

If you ever mess up the configuration you can always modify the settings through the graphical interface of the control panel. From Start > Control Panel > Switch to Classic View, and open Network Connections


Before running these commands, look at your existing (working) IP configuration with the ipconfig command:
This will show you the Default Gateway and DNS entries to put in the commands above where the {braces} are.
================================
C:\Documents and Settings\2xod>ipconfig /all

Windows IP Configuration

Host Name . . . . . . . . . . . . : computar
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Intel(R) PRO/1000 XT Server Adapter
Physical Address. . . . . . . . . : 00-02-B3-B5-D6-J3
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.0.101
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.2
DNS Servers . . . . . . . . . . . : 192.168.0.2

C:\Documents and Settings\2xod>
================================

nitul - Nov 17, 2008 4:26am GMT
Go to services and find DNS client modify it as manual not automatic.Give the DNS manualy and will work.
justbow - Dec 10, 2008 6:47am GMT
i use windows 2000 then set :

-----------------
@echo off
netsh interface ip set address name="Local Area Connection" static 172.28.13.7 255.255.255.224 172.28.13.30
ipconfig
pause
---------------------


the ip configuration become :
IP Address : 172.28.13.7
Netmask : 255.255.255.224
Gateway : 172.28.13.30

then running the different script :

@echo off
netsh interface ip set address name="Local Area Connection" static 172.28.13.92 255.255.255.240
ipconfig
pause

the ip configuration become :
IP Address : 172.28.13.92
Netmask : 255.255.255.240
Gateway : 172.28.13.30

the Gateway still unchange..
I want no gateway for this :D
Any solution?
kmaniyar - Nov 5, 2009 10:18pm GMT
I have installed couple of NIC cards on my Windows 7 PC. I would like to set the IP address of these interfaces to 0.0.0.0, but the cmd: netsh does not allow to set the IP 0.0.0.0 ?

C:\>netsh int ip set address "Local Area Connection 2" static 0.0.0.0 mask=255.255.255.0
The parameter is incorrect.

Is there a way to set the IP to 0.0.0.0 from netsh command?
Answer
+4
moins plus
Great help on the above posting.

Is it possible to use IF/Els conditional script between HDCP and static changes?

Suppose: When I run my script it will look for value DHCP=YES then it will run static IP change scripts and when it will find the Value DHCP=NO it will run the DHCP set script.

as an example:
=============
If DHCP = yes
then run Batch1

else skip

Batch1
netsh int IP set address "local area connection" static 192.168.1.12 255.255.255.0 192.168.1.1 1
netsh int ip set dns "local area connection" static 192.168.0.254 primary
netsh int ip set dns "local area connection" static 192.168.0.253 secondary

If DHCP = no
then run Batch2

Batch2
netsh int ip set address "local area connection" dhcp
netsh int ip set dns "local area connection" dhcp
===========================

something like that.

Is it possible. Would appreciate your help on this.

oyabin - Jan 10, 2009 3:12pm GMT
um may i ask...
how about connecting to wireless network, does anyone know how to do it in cmd?
Claul - Jan 30, 2009 8:17pm GMT
Secondary dns cannot be set as you describe. If you want you have to use add like this:
netsh int ip add dns "local area connection" 0.0.0.0 index=2
Of course, you have to use other figures for dns not 0.0.0.0.
Susanta - Jul 13, 2009 9:34am BST
Secondary DNS not accepting its showing "secondary is not an acceptable value for register."
Answer
+2
moins plus
how to create batch file (to Run from cmd) to repair option in Local Area Network.

Answer
+1
moins plus
Hello,

There's no way to effectively change it from a command prompt. You could use the ipconfig release and renew commands, but chances are you're just going to get your old IP address back, especially if you are behind a router or static IP.


Hope this will help you.

LarryFromVegas - Feb 20, 2010 3:08pm GMT
When you execute NETSH commands from the command prompt, do they only last for the current Windows session or are they made permanent and are still in effect after reboot?
loukascy - Nov 30, 2009 2:26pm GMT
hey my friend how can i change my computer's ip?
jake - Apr 29, 2011 6:45pm BST
It is persistant, Wouldn't make much sense if you were a normal statically IP configured user and it changes upon reboot? That would mess up every server on the planet, netsh is just another avenue into the network connections manager.
Answer
+1
moins plus
in command line write ipconfig /renew EL*

Answer
+1
moins plus
to change DNS 
Before running these commands, look at your existing (working) IP configuration with the ipconfig command: 
This will show you the Default Gateway and DNS entries to put in the commands above where the {braces} are. 
================================ 
C:\Documents and Settings\2xod>ipconfig /all 

Windows IP Configuration 

Host Name . . . . . . . . . . . . : computar 
Primary Dns Suffix . . . . . . . : 
Node Type . . . . . . . . . . . . : Unknown 
IP Routing Enabled. . . . . . . . : No 
WINS Proxy Enabled. . . . . . . . : No 

Ethernet adapter Local Area Connection: 

Connection-specific DNS Suffix . : 
Description . . . . . . . . . . . : Intel(R) PRO/1000 XT Server Adapter 
Physical Address. . . . . . . . . : 00-02-B3-B5-D6-J3 
Dhcp Enabled. . . . . . . . . . . : No 
IP Address. . . . . . . . . . . . : 192.168.0.101 
Subnet Mask . . . . . . . . . . . : 255.255.255.0 
Default Gateway . . . . . . . . . : 192.168.0.2 
DNS Servers . . . . . . . . . . . : 192.168.0.2 

C:\Documents and Settings\astana translations group>
netsh int ip set dns "local area connection" static 192.168.0.254 primary 

This is assuming 3 things. 
1) The network adapter you're trying to change the IP for is "local area connection". It could also be "local area connection 2" or "wireless network connection". Look in your control panel for the correct name 
2) The IP you want to set is 192.168.0.101, change this to whatever IP to want to use. 
3) The default gateway and dns are the same IP. If you are using some kind of router they usually are. Change this to match your network config found with the command ipconfig /all 

You will need to run both commands to change the IP.





So how do I change a preferred DHCP ip address?

Answer
+1
moins plus
if ur command prompt there type command as ipconfig\all, then type the ipconfig\release then ipconfig\renew that's all

Answer
+1
moins plus
Hey everyone you will love this. This is the answer to your questions:

Just edit the name of the network connection, change IPs and save it as a batch file. Voila...

@ECHO OFF

set varip=172.20.16.131
set varsm=255.255.252.0
set vargw=172.20.16.1
set vardns1=172.20.0.16
set vardns2=
set varhome=http://www.google.com


ECHO Setting IP Address and Subnet Mask
netsh int ip set address name = "Wireless Network Connection" source = static addr = %varip% mask = %varsm%

ECHO Setting Gateway
netsh int ip set address name = "Wireless Network Connection" gateway = %vargw% gwmetric = 1

ECHO Setting Primary DNS
netsh int ip set dns name = "Wireless Network Connection" source = static addr = %vardns1%

ECHO Setting Secondary DNS
netsh int ip add dns name = "Wireless Network Connection" addr = %vardns2%

ECHO Setting Internet Explorer Homepage to %varhome%
reg add "hkcu\software\microsoft\internet explorer\main" /v "Start Page" /d "%varhome%" /f

rem ECHO Here are the new settings for %computername%:
rem netsh int ip show config

pause

Answer
+1
moins plus
please i really do need assistance on how to install an automatic Usa IP on my computer. I use windows XP. any assistance would be deeply and genuinely appreciated.

Answer
+0
moins plus
Create a text doc, and copy then paste the following to the text document.

@ECHO OFF
ipconfig /release
ipconfig /flushdns
ipconfig /setclassid
ipconfig /registerdns
ipconfig /renew
EXIT



Then go to file - save as, let the window open, and under Save As Type select All Files and name as fix.bat, click save and exit.
Go to where you saved file and double click on it, let it do it's thing and it will be fixed!

Answer
+0
moins plus
I can help you with proxy IP Change. add me Yahoo Mass go4buy

Answer
+0
moins plus
Iam unable to assign ip address through command prompt in win98?
please help me?

GiantLeap- Dec 1, 2008 9:19pm GMT
you can't assign ip addresses from CMD in windows 98/me/nt systems
Answer
+0
moins plus
2xod.com:
I asked you yesterday, but you deleted my question, probably that is because you don't know how to do it.
But my question is - how to change preferred IP address which is requested by DHCP-clients?

Astana Translations Group

Answer
+0
moins plus
In Run menu enter cmd press enter
type ipconfig for display the IP address of the PC.
For renew ipconfig/renew
For release ipconfig/release

GiantLeap- Dec 2, 2008 6:50am GMT
omg, just click "Repair" in XP or "Diagnose" in Vista/Windows7 at your network connection
Answer
+0
moins plus
lot of free tools on net which can tell u what u want. ip scaner is one of the tool. you just go on google and search u can find it if no than go to http://www.download.com/...

this link and download that software and than install.

GiantLeap- Dec 2, 2008 2:19pm GMT
Have you seen any DHCP preferred IP changer? thx)
Answer
+0
moins plus
how to change other IP from mycomputer....??

Answer
+0
moins plus
hello
you can use the command ipconfig renew

EHJ - Aug 28, 2009 1:02pm BST
IP.VBS

' Assign a Static IP Address


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

strIPAddress = Array("192.168.90.49")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.90.2")
strGatewayMetric = Array(1)
strDNSServers = Array("192.168.90.6")

For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNSServers)
Next

WScript.Echo "Iptalan er nú 192.168.90.49."

Back to DHCP

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
Next
WScript.Echo "DHCP hefur nú verið virkjað."
danny - Oct 9, 2009 10:07am BST
i am trying to configure my ip address using command prompt but i have an error message "invalid interface local area connecti
on specified" what can i do next
tekolaEHJ - Feb 9, 2010 2:24pm GMT
After 2 days of frustration, the solution above worked ...THANKS

Here it is again:
To change the IP from the command prompt. Windows XP
I put it in a .BAT file

The command is:
rem to change IP and default gateway:
netsh int ip set address "Wireless Network Connection 2" static 192.168.2.101 255.255.255.0 192.168.2.1 1
rem to change DNS:
netsh int ip set dns "Wireless Network Connection 2" static 192.168.2.1 primary

This is assuming 3 things.
1) The network adapter is "Wireless Network Connection 2" from "ipconfig /all"
2) The NEW IP is 192.168.2.101,
3) The default gateway and dns are the same IP. also from "ipconfig /all"

You will need to run both commands to change the IP.
Answer
+0
moins plus
ipconfig

Answer
+0
moins plus
How do I alternate automatically between ip address in the same batch file.

e.g.

192.168.1.10

or

192.168.1.13

1 2 3 4 5 Next
This document entitled « How to change IP address from command prompt » from Kioskea.net (en.kioskea.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the licence, as this note appears clearly.
How to change IP address from command prompt - page 2