How to change IP address from command prompt?

Solved/Closed
nareen123 Posts 10 Registration date Tuesday April 15, 2008 Status Member Last seen May 29, 2009 - Updated on Jan 19, 2019 at 12:32 AM
netguy2000 Posts 1 Registration date Wednesday November 28, 2012 Status Member Last seen November 28, 2012 - Nov 28, 2012 at 12:53 AM
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
Related:

11 replies

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!
167
how to revert back? when I use your method my internet connection was lost.
0
did u regain the connection??? if not, go to network connections right click on the local area connection-properties-internet protocol properties.
now select-1. obtain ip address automatically
2. obtain dns automatically.
hope it helped... I also faced the same problem..
0
Arun Kaliraja.B > Romulus
Feb 10, 2010 at 12:30 AM
Hi

I am facing one such problem in windows 7!!

the problem is if I revert it back to automaitic configuration it is not getting reverted back!! :(..

It is remembering my ip and subnet mask.

so I am not able to even connect to my lan..

what is the solution for this?
0
How do I change a preferred DHCP address?

---
http://interpret.astana-translation.ath.cx
0
can you please step by step explain how to change my wireless (connected to a router) ip address.

if you can thankyou very much
0
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>
================================
30
how to set both the preferred and alternate dns using dos??
0
thepenk > bharat.cse1
Sep 23, 2008 at 02:28 AM
You can add more than one DNS server with the commands:

netsh int ip set dns "local area connection" static 192.168.0.254 primary
netsh int ip add dns "local area connection" 192.168.1.254
0
Paddy > thepenk
Mar 7, 2009 at 05:11 AM
thank you for your help.
0
jitendar > bharat.cse1
Aug 18, 2009 at 02:01 AM
how to add or change alternate dns server




Thanks and regards
0
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?
0
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.
9
um may I ask...
how about connecting to wireless network, does anyone know how to do it in cmd?
0
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.
0
Secondary DNS not accepting its showing "secondary is not an acceptable value for register."
0
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!
5

Didn't find the answer you are looking for?

Ask a question
yashmaur Posts 14 Registration date Tuesday April 15, 2008 Status Member Last seen May 29, 2009 5
Jul 8, 2008 at 05:44 AM
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.
4
GiantLeap Posts 85 Registration date Saturday November 29, 2008 Status Member Last seen December 8, 2008 45
Nov 30, 2008 at 07:55 AM
Can somebody tell me how to change DHCP preferred IP???????????? Thx!
0
number 1 I hack all the time I could hack your computer change everything and its ip in an 1hr and the change ip wouldnt change ip adress always change
0
Hack my magic stick, you dumbass!
0
nat123 > nimron
Jun 16, 2009 at 06:56 AM
hahahahahaahahahhahahahaha lmao!!!!!!!!!!!!!!!!!!!!!!!! this was very helpful ty.
0
how to change ip address from commandprompt
0
Mangesh Gunjal
Jan 29, 2010 at 08:14 AM
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.
2
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
1
GiantLeap Posts 85 Registration date Saturday November 29, 2008 Status Member Last seen December 8, 2008 45
Dec 2, 2008 at 01:50 AM
omg, just click "Repair" in XP or "Diagnose" in Vista/Windows7 at your network connection
0
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=https://www.google.com/?gws_rd=ssl


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
0
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
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
0
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.
0
you want a pseudo interface, just google it. Server 2008 is setup with pseudo interfaces.
0
netguy2000 Posts 1 Registration date Wednesday November 28, 2012 Status Member Last seen November 28, 2012
Nov 28, 2012 at 12:53 AM
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
0