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

Posts
10
Registration date
Tuesday April 15, 2008
Status
Member
Last seen
May 29, 2009
-
Hello,

Is there any way to change IP address of the 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.
System Configuration: Windows XP Internet Explorer 6.0
See more 

11 replies

Best answer
approved by Ratnendra Ashok on Jan 19, 2019
166
Thank you
Hi,

You can change the IP from the command prompt. Here are the commands:
  • 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.

Hope, it works!

Say "Thank you" 166

A few words of thanks would be greatly appreciated. Add comment

CCM 6409 users have said thank you to us this month

Unfortenately not.
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?
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
it won't work..
it work , Run command prompt from Administrator privilege
30
Thank you
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>
================================
> bharat.cse1 -
how to add or change alternate dns server




Thanks and regards
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?
> Armoredfish -
Go to services and find DNS client modify it as manual not automatic.Give the DNS manualy and will work.
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?
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?
9
Thank you
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.
um may I ask...
how about connecting to wireless network, does anyone know how to do it in cmd?
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.
Secondary DNS not accepting its showing "secondary is not an acceptable value for register."
6
Thank you
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
5
Thank you
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!
Posts
14
Registration date
Tuesday April 15, 2008
Status
Member
Last seen
May 29, 2009
5
4
Thank you
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.
start the run>cmd
type the command: netsh interface set ip address "local area network" static 192.168.1.10
than enter
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
> yogesh -
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?
hey my friend how can I change my computer's ip?
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.
2
Thank you
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.
1
Thank you
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
Posts
90
Registration date
Saturday November 29, 2008
Status
Member
Last seen
December 8, 2008
45 -
omg, just click "Repair" in XP or "Diagnose" in Vista/Windows7 at your network connection
0
Thank you
hello u can change ip address in windows xp with following procedure...

1. Click on "Start" in the bottom left hand corner of screen.
2. Click on "Run".
3. Type in "command" and hit Okay. You should now be at an MSDOS prompt screen.
4. Type "ipconfig /release" and hit "Enter". This will disable your internet connection. To undo it, type "ipconfig /renew".
5. Type "exit" and leave the prompt.
6. Right-click on "Network Places" or "My Network Places" on your desktop.
7. Click on "Properties". You should now be on a screen with something titled "Local Area Connection", or something close to that, and, if you have a network hooked up, all of your other networks.
8. Right-click on "Local Area Connection" and click "Properties".
9. Double-click on the "Internet Protocol (TCP/IP)" from the list under the "General" tab.
10. Click on "Use the following IP address" under the "General" tab.
11. Create an IP address. (It doesn't matter what it is.)
12. Press "Tab" and it should automatically fill in the "Subnet Mask" section with default numbers.
13. Click the "Ok" button.
14. Click the "Ok" button. You should now be back to the "Local Area Connection" screen.
15. Right-click back on "Local Area Connection" and go to properties again.
16. Go back to the "TCP/IP" settings.
17. Select "Obtain an IP address automatically".
18. Click the "Ok" button.
19. Click the "Ok" button.
20. You now have a new IP address
0
Thank you
first of all we mush follow the step bellow :

1/tye cmd
2/type netsh int ip set address "local area connection" static 192.168.0.101 255.255.255.0 192.168.0.254 1
for "local area connection" it is the name of network adapter for example if your natwork adapter name is local area connecton .so we type netsh int ip set address "local area connection" static 192.168.0.101 255.255.255.0 192.168.0.254 1
to see your network adapter name go to controll panel networkconnection
note for the example abow
192.168.0.101 is ip address
255.255.255.0 is subnetmask
192.168.0.254 1 is default getway
I dont want to change the pre configured ip address, but I want to add a new ip of diffrent network, being merged with it.
you want a pseudo interface, just google it. Server 2008 is setup with pseudo interfaces.
Posts
1
Registration date
Wednesday November 28, 2012
Status
Member
Last seen
November 28, 2012
0
Thank you
I am using a script to change IP from DOS with the help "netsh" and "devcon" in XP. see the following. (there is also an another way in DOS to change IP, if you don't agree with this script then plz ask again)

@echo off
:::To find out your network card instances (wifi_ins and wire_ins) use following command "devcon listclass net"

set wifi_name=WiFi
set wire_name=WIRELAN
set wire_ip=192.168.0.117
set wire_mask=255.255.252.0
set wire_gw=192.168.0.130
set wifi_ip=192.168.105.117
set wifi_mask=255.255.255.0
set wifi_gw=192.168.105.130
set dns1=4.2.2.1
set dns2=4.2.2.2
set dns3=4.2.2.3
set dns4=4.2.2.4
set "wire_ins=PCI\VEN_10EC*"
set "wifi_ins=USB\VID_0BDA*"

goto select
:select
echo.
echo.
echo SELECT YOUR PREFERD NETWORK CONNECTION
echo.
echo.
echo [1] Office WIRE Network
echo [2] Office WIFI Network
echo [X] Exit
echo.
:network
@echo off
SET /P E=[1, 2, X]?
for %%? in (1) do if /I "%E%"=="%%?" goto wire
for %%? in (2) do if /I "%E%"=="%%?" goto wifi
for %%? in (X) do if /I "%E%"=="%%?" goto end

goto select

:wire
@echo off
echo "Enabling Wire Interface and Disabling WiFi"
echo.
devcon disable "%wifi_ins%"
echo.
netsh int ip set address "%wifi_name%" source = dhcp
echo.
netsh int ip set dns "%wifi_name%" dhcp
echo.
echo Setting IP, MASK, and Gateway
netsh interface ip set address "%wire_name%" static %wire_ip% %wire_mask% %wire_gw% 1
echo Setting DNS Primary
netsh interface ip set dns "%wire_name%" static %dns1%
echo Setting DNS Secondary
netsh interface ip add dns "%wire_name%" %dns2% index=2
echo.
devcon enable "%wire_ins%"
echo.
sleep 5

goto end


:wifi
@echo off
echo.
echo "Enabling WiFi Interface and Disabling Wire"
echo.
devcon disable "%wire_ins%"
echo.
netsh int ip set address "%wire_name%" source = dhcp
echo.
netsh int ip set dns "%wire_name%" dhcp
echo.
echo Setting IP, MASK, and Gateway
netsh interface ip set address "%wifi_name%" static %wire_ip% %wire_mask% %wire_gw% 1
echo Setting DNS Primary
netsh interface ip set dns "%wifi_name%" static %dns1%
echo Setting DNS Secondary
netsh interface ip add dns "%wifi_name%" %dns2% index=2
echo.
devcon enable "%wifi_ins%"
echo.
sleep 5

goto end

:end