Ask a question Report

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

nareen123 10Posts Tuesday April 15, 2008Registration date May 29, 2009Last seen - Latest answer on Nov 28, 2012 12:53AM
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 
Answer
+129
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 08:12AM
Unfortenately not.
ALA- Jan 5, 2010 10:31PM
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 08:36AM
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
candy- Oct 23, 2012 12:56AM
it won't work..
sabit ali- Oct 30, 2012 01:08PM
it work , Run command prompt from Administrator privilege
Answer
+29
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>
================================

jitendar bharat.cse1 - Aug 18, 2009 02:01AM
how to add or change alternate dns server




Thanks and regards
Armoredfish- Nov 15, 2008 05:38AM
I was reading your replies. You appear to be a master. I have the following problems which have croppoed up:

--I use an old Windows 2003 Enterprise Server on my C Drive of the my Dell Server (use it as a home PC). Does not have a Service Pack(s). It had a Enterpise version of MsAfee as a anitvirus pkg. However I made the mistake of installing a false codec ( a virus/trojan) for my multi media player. As a result for a few days the trojan though detectable and deleted by McAfee which detects and deletes it on some kind of access. However, the trojan/virus has been consistently modifying my DNS addresses (2 of them) and whenever I try to modify them by typing in the original ones it changes it with a set of its own DNS address. McAfee is not able to help even after running it in the safe mode.

-To acess the Internet now - I have installed Vista in another partition and get it through DHCP - it obtains IP and DNS of the router and beyond automatically. That works in Vista. But does not work in the C: drive which has fixed IP and DNS addresses.

-What do you advise?
nitul- Nov 16, 2008 11:26PM
Go to services and find DNS client modify it as manual not automatic.Give the DNS manualy and will work.
justbow- Dec 10, 2008 01:47AM
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 05:18PM
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
+9
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 10:12AM
um may i ask...
how about connecting to wireless network, does anyone know how to do it in cmd?
Claul- Jan 30, 2009 03:17PM
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 04:34AM
Secondary DNS not accepting its showing "secondary is not an acceptable value for register."
Answer
+6
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
+5
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
+5
moins plus
if ur command prompt there type command as ipconfig\all, then type the ipconfig\release then ipconfig\renew that's all

Answer
+5
moins plus
how to create batch file (to Run from cmd) to repair option in Local Area Network.

Answer
+4
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.

yogesh- Feb 20, 2010 02:10AM
start the run>cmd
type the command: netsh interface set ip address "local area network" static 192.168.1.10
than enter
yogesh baba - Feb 20, 2010 02:15AM
start the run>cmd
type the command:
netsh interface ip set address "Local Area Connection" static 192.168.142.102 255.255.255.0 192.168.142.1 2



or


cmd > netsh>inter>add ip address "local area network" static 192.168.1.10
finish
LarryFromVegas- Feb 20, 2010 10:08AM
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 09:26AM
hey my friend how can i change my computer's ip?
jake- Apr 29, 2011 01:45PM
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
+4
moins plus
Thats of great help. Thanks a bunch and keep up the great work

Mash

Answer
+3
moins plus
in command line write ipconfig /renew EL*

Answer
+3
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
+2
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
+2
moins plus
Hey i can help you i hack all the time and work with ip adreess email me at jasbll333@msn.com

Answer
+2
moins plus
http://www.myiptest.com - All Network tools in one place

Answer
+2
moins plus
Here is a tutorial about how to change your ip address from command prompt: http://www.petri.co.il/configure_tcp_ip_from_cmd.htm
I use IP Privacy to change my ip address: http://www.privacy-pro.com

Answer
+2
moins plus
netsh int ip set address name = "Local Area Connection" source = static addr =192.168.0.0 mask = 255.255.255.0
netsh int ip set address name = "Local Area Connection" gateway =192.168.0.0 gwmatric = 1
netsh int ip set dns name = "Local Area Conncetion" source = static addr = 192.168.0.0
netsh int ip set dns name = "Local Area Conncetion" addr = 192.168.0.0

Note:make a bat file with above contents & Run.

Answer
+1
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
+1
moins plus
Hi! This was a great article - it didn't exactly work for me out-of-the-box, but inspired me and helped me create my own solution.

I've posted that at: http://theci.wordpress.com/...

It allows selection of an appropriate IP & DNS "profile" in Windows Vista, some folks might find that useful.

Thanks,
Sid

Answer
+1
moins plus
1 2 3 4 5 Next
This document entitled « How to change IP address from command prompt » from Kioskea (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 license, as this note appears clearly.

Not a member yet?

sign-up, it takes less than a minute and it's free!

Members get more answers than anonymous users.

Being a member gives you detailed monitoring of your requests.

Being a member gives you additional options.