- Buying Guides

Complete Guides by How-To Geek
Our latest product roundups, reader favorites, more from how-to geek, latest geek news, latest reviews, across lifesavvy media.
Join 425,000 subscribers and get a daily digest of news, geek trivia, and our feature articles.
By submitting your email, you agree to the Terms of Use and Privacy Policy .
How to Change Your IP Address From the Command Prompt in Windows
Walter Glenn is a former Editorial Director for How-To Geek and its sister sites. He has more than 30 years of experience in the computer industry and over 20 years as a technical writer and editor. He's written hundreds of articles for How-To Geek and edited thousands. He's authored or co-authored over 30 computer-related books in more than a dozen languages for publishers like Microsoft Press, O'Reilly, and Osborne/McGraw-Hill. He's also written hundreds of white papers, articles, user manuals, and courseware over the years. Read more...

It’s easy enough to change an IP address on your PC using Control Panel, but did you know you can also do it from the Command Prompt?
Changing your IP address with the Control Panel interface isn’t difficult, but it does require clicking through a number of different windows and dialog boxes. If you’re a fan of the Command Prompt, though, you can get it done more quickly using the netsh command, which is just one of the great network utilities built into Windows .
The netsh command allows you to configure just about any aspect of your network connections in Windows. To work with it, you’ll need to open Command Prompt with administrative privileges. In Windows 10 or 8.1, right-click the Start menu (or press Windows+X on your keyboard) and choose “Command Prompt (Admin).” In previous versions of Windows, search Start for “command prompt” and then right-click the result and choose “Run as Administrator.”
RELATED: How to Find Your Private and Public IP Addresses
View Your Network Information
Before you change your IP address and related information, you’ll need to find the full name of the network for the interface you want to change. To do this, type the following command:
RELATED: How to Enable CTRL+C / Ctrl+V for Pasting in the Windows Command Prompt
Scroll down until you see the interface you’re looking for. In our example, we’re going to modify the Wi-Fi interface, which on our machine is just named “Wi-Fi.” You’ll also see other default names that Windows assigns to interfaces, such as “Local Area Connection,” “Local Area Connection* 2,” and “Ethernet.” Just find the one you’re looking for and make note of the exact name. You can also copy and paste the name to Notepad and then back into Command Prompt later to make things easier.
Change Your IP Address, Subnet Mask, and Default Gateway
With the interface name in hand, you’re ready to change the IP Address, subnet mask, and gateway. To do this, you’ll issue a command using the following syntax:
So, for example, your command might look something like the following:
where the info is replaced by whatever you want to use. In our example, the command does the following:
- Uses the interface name “Wi-Fi”
- Sets the IP address to 192.168.3.1
- Sets the subnet mask to 255.255.255.0
- Sets the default gateway to 192.168.3.1
And if you’re using a static IP address but want to switch to using an IP address assigned automatically by a DHCP server–such as your router–you can use the following command instead:
Change Your DNS Settings
RELATED: The Ultimate Guide to Changing Your DNS Server
You can also use the netsh command to change the DNS servers used by a network interface. Third-party DNS servers–like Google Public DNS and OpenDNS –can be faster and more reliable than the DNS servers provided by your ISP. Whatever your reason for changing your DNS server , you can do it either at the router so it affects all the devices that get their information from the router or at the individual device. If you want to change the DNS servers for just one PC, it’s easy to do with the netsh command.
You’ll need to use the command twice: once to set your primary DNS server and once to set your secondary, or backup, DNS server. To set your primary DNS server, use the following syntax:
So, for example, your command might look something like the following (in which we set it to Google’s primary public DNS server, 8.8.8.8):
To set your secondary DNS server, you’ll use a very similar command:
So, continuing our example, you might set your secondary DNS as the Google Public DNS secondary server, which is 8.8.4.4:
And just like with the IP address, you can also change it so that the network interface grabs its DNS settings automatically from a DHCP server instead. Just use the following command:
And there you have it. Whether you like typing at the command prompt better or just want to impress your coworkers, now you know all the command line magic you need for changing your IP address settings.
- › How to Change Your IP Address
- › How to Change Your IP Address Using PowerShell
- › How to Find Your IP Address From CMD (Command Prompt)
- › How to Fix “Your Connection Is Not Private” Errors
- › How to Get Free Steam Games
- › How to Watch UFC 285 Jones vs. Gane Live Online
- › How to Win $2000 By Learning to Code a Rocket League Bot
- › The Quest 2 and Quest Pro VR Headsets Are Dropping in Price
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Netsh Command Syntax, Contexts, and Formatting
- 7 minutes to read
- 6 contributors
Applies to: Windows Server 2022, Windows Server 2019, Windows Server 2016, Azure Stack HCI, versions 21H2 and 20H2
You can use this topic to learn how to enter netsh contexts and subcontexts, understand netsh syntax and command formatting, and how to run netsh commands on local and remote computers.
Netsh is a command-line scripting utility that allows you to display or modify the network configuration of a computer that is currently running. Netsh commands can be run by typing commands at the netsh prompt and they can be used in batch files or scripts. Remote computers and the local computer can be configured by using netsh commands.
Netsh also provides a scripting feature that allows you to run a group of commands in batch mode against a specified computer. With netsh, you can save a configuration script in a text file for archival purposes or to help you configure other computers.
Netsh contexts
Netsh interacts with other operating system components by using dynamic-link library (DLL) files.
Each netsh helper DLL provides an extensive set of features called a context , which is a group of commands specific to a networking server role or feature. These contexts extend the functionality of netsh by providing configuration and monitoring support for one or more services, utilities, or protocols. For example, Dhcpmon.dll provides netsh with the context and set of commands necessary to configure and manage DHCP servers.
Obtain a list of contexts
You can obtain a list of netsh contexts by opening either command prompt or Windows PowerShell on a computer running Windows Server 2016 or Windows 10. Type the command netsh and press ENTER. Type /? , and then press ENTER.
Following is example output for these commands on a computer running Windows Server 2016 Datacenter.
PS C:\Windows\system32> netsh netsh>/? The following commands are available: Commands in this context: .. - Goes up one context level. ? - Displays a list of commands. abort - Discards changes made while in offline mode. add - Adds a configuration entry to a list of entries. advfirewall - Changes to the `netsh advfirewall' context. alias - Adds an alias. branchcache - Changes to the `netsh branchcache' context. bridge - Changes to the `netsh bridge' context. bye - Exits the program. commit - Commits changes made while in offline mode. delete - Deletes a configuration entry from a list of entries. dhcpclient - Changes to the `netsh dhcpclient' context. dnsclient - Changes to the `netsh dnsclient' context. dump - Displays a configuration script. exec - Runs a script file. exit - Exits the program. firewall - Changes to the `netsh firewall' context. help - Displays a list of commands. http - Changes to the `netsh http' context. interface - Changes to the `netsh interface' context. ipsec - Changes to the `netsh ipsec' context. ipsecdosprotection - Changes to the `netsh ipsecdosprotection' context. lan - Changes to the `netsh lan' context. namespace - Changes to the `netsh namespace' context. netio - Changes to the `netsh netio' context. offline - Sets the current mode to offline. online - Sets the current mode to online. popd - Pops a context from the stack. pushd - Pushes current context on stack. quit - Exits the program. ras - Changes to the `netsh ras' context. rpc - Changes to the `netsh rpc' context. set - Updates configuration settings. show - Displays information. trace - Changes to the `netsh trace' context. unalias - Deletes an alias. wfp - Changes to the `netsh wfp' context. winhttp - Changes to the `netsh winhttp' context. winsock - Changes to the `netsh winsock' context. The following sub-contexts are available: advfirewall branchcache bridge dhcpclient dnsclient firewall http interface ipsec ipsecdosprotection lan namespace netio ras rpc trace wfp winhttp winsock To view help for a command, type the command, followed by a space, and then type ?.
Subcontexts
Netsh contexts can contain both commands and additional contexts, called subcontexts . For example, within the Routing context, you can change to the IP and IPv6 subcontexts.
To display a list of commands and subcontexts that you can use within a context, at the netsh prompt, type the context name, and then type either /? or help . For example, to display a list of subcontexts and commands that you can use in the Routing context, at the netsh prompt (that is, netsh> ), type one of the following:
routing help
To perform tasks in another context without changing from your current context, type the context path of the command you want to use at the netsh prompt. For example, to add an interface named "Local Area Connection" in the IGMP context without first changing to the IGMP context, at the netsh prompt, type:
routing ip igmp add interface "Local Area Connection" startupqueryinterval=21

Running netsh commands
To run a netsh command, you must start netsh from the command prompt by typing netsh and then pressing ENTER. Next, you can change to the context that contains the command you want to use. The contexts that are available depend on the networking components that you have installed. For example, if you type dhcp at the netsh prompt and press ENTER, netsh changes to the DHCP server context. If you do not have DHCP installed, however, the following message appears:
The following command was not found: dhcp.
Formatting Legend
You can use the following formatting legend to interpret and use correct netsh command syntax when you run the command at the netsh prompt or in a batch file or script.
- Text in Italic is information that you must supply while you type the command. For example, if a command has a parameter named - UserName , you must type the actual user name.
- Text in Bold is information that you must type exactly as shown while you type the command.
- Text followed by an ellipsis (...) is a parameter that can be repeated several times in a command line.
- Text that is between brackets [ ] is an optional item.
- Text that is between braces { } with choices separated by a pipe provides a set of choices from which you must select only one, such as {enable|disable} .
- Text that is formatted with the Courier font is code or program output.
Running Netsh commands from the command prompt or Windows PowerShell
To start Network Shell and enter netsh at the command prompt or in Windows PowerShell, you can use the following command.
Netsh is a command-line scripting utility that allows you to, either locally or remotely, display or modify the network configuration of a currently running computer. Used without parameters, netsh opens the Netsh.exe command prompt (that is, netsh> ).
netsh [ -a AliasFile ] [ -c Context ] [ -r RemoteComputer ] [ -u [ DomainName\ ] UserName ] [ -p Password | *] [{ NetshCommand | -f ScriptFile }]
Optional. Specifies that you are returned to the netsh prompt after running AliasFile .
Optional. Specifies the name of the text file that contains one or more netsh commands.
Optional. Specifies that netsh enters the specified netsh context.
Optional. Specifies the netsh context that you want to enter.
Optional. Specifies that you want the command to run on a remote computer.
When you use some netsh commands remotely on another computer with the netsh –r parameter, the Remote Registry service must be running on the remote computer. If it is not running, Windows displays a “Network Path Not Found” error message.
RemoteComputer
Optional. Specifies the remote computer that you want to configure.
Optional. Specifies that you want to run the netsh command under a user account.
DomainName\\
Optional. Specifies the domain where the user account is located. The default is the local domain if DomainName\ is not specified.
Optional. Specifies the user account name.
Optional. Specifies that you want to provide a password for the user account.
Optional. Specifies the password for the user account that you specified with -u UserName .
NetshCommand
Optional. Specifies the netsh command that you want to run.
Optional. Exits netsh after running the script that you designate with ScriptFile .
Optional. Specifies the script that you want to run.
Optional. Displays help at the netsh prompt.
If you specify -r followed by another command, netsh runs the command on the remote computer and then returns to the Cmd.exe command prompt. If you specify -r without another command, netsh opens in remote mode. The process is similar to using set machine at the Netsh command prompt. When you use -r , you set the target computer for the current instance of netsh only. After you exit and reenter netsh , the target computer is reset as the local computer. You can run netsh commands on a remote computer by specifying a computer name stored in WINS, a UNC name, an Internet name to be resolved by the DNS server, or an IP address.
Typing parameter string values for netsh commands
Throughout the Netsh command reference there are commands that contain parameters for which a string value is required.
In the case where a string value contains spaces between characters, such as string values that consist of more than one word, it is required that you enclose the string value in quotation marks. For example, for a parameter named interface with a string value of Wireless Network Connection , use quotation marks around the string value:
interface="Wireless Network Connection"
Submit and view feedback for
Additional resources
- Stack Overflow Public questions & answers
- Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
- Talent Build your employer brand
- Advertising Reach developers & technologists worldwide
- About the company
Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
How can you change Network settings (IP Address, DNS, WINS, Host Name) with code in C#
I am developing a wizard for a machine that is to be used as a backup of other machines. When it replaces an existing machine, it needs to set its IP address, DNS, WINS, and host name to match the machine being replaced.
Is there a library in .net (C#) which allows me to do this programatically?
There are multiple NICs, each which need to be set individually.
Thank you TimothyP for your example. It got me moving on the right track and the quick reply was awesome.
Thanks balexandre . Your code is perfect. I was in a rush and had already adapted the example TimothyP linked to, but I would have loved to have had your code sooner.
I've also developed a routine using similar techniques for changing the computer name. I'll post it in the future so subscribe to this questions RSS feed if you want to be informed of the update. I may get it up later today or on Monday after a bit of cleanup.
- configuration
- I hope you don't mind me sending you to an example, but this is really a perfect example: http://www.codeproject.com/KB/cs/oazswitchnetconfig.aspx – TimothyP Oct 16, 2008 at 19:01
7 Answers 7
Just made this in a few minutes:
- 4 just like EnableStatic, is there any way to programatically switch the IP back to dynamic? EnableDynamic? I want to build a tool to toggle between a static and dynamic IP with one click. Thanks. – aalaap Nov 8, 2011 at 7:48
- 7 For those interested, you can find a list of all the properties and methods on this ManagementObject here: msdn.microsoft.com/en-us/library/aa394217.aspx – Paccc Dec 19, 2012 at 18:36
- 1 @balexandre how can we make workable under limited user account? – Eric Jan 2, 2013 at 12:35
- 1 @aalaap you can use EnableDHCP – balexandre Nov 20, 2013 at 12:44
- 3 In case someone else is wondering, to reset the DNS servers to "Automatic" just set the DNSSearverSearchOrder to null. e.g. newDNS["DNSServerSearchOrder"] = null; – Sverrir Sigmundarson Jan 9, 2016 at 20:25
Refactored the code from balexandre a little so objects gets disposed and the new language features of C# 3.5+ are used (Linq, var, etc). Also renamed the variables to more meaningful names. I also merged some of the functions to be able to do more configuration with less WMI interaction. I removed the WINS code as I don't need to configure WINS anymore. Feel free to add the WINS code if you need it.
For the case anybody likes to use the refactored/modernized code I put it back into the community here.
- 1 what is the parameter 'nic' meant to contain in the setNameservers function? – clamp Jul 7, 2014 at 15:29
- its the name (description) of the network interface. you can enumerate them using NetworkInterface.GetAllNetworkInterfaces(). – Marc Jul 8, 2014 at 5:28
- 2 Note: you must add a reference to System.Management to your project. – Jeff Mar 10, 2016 at 18:28
I like the WMILinq solution. While not exactly the solution to your problem, find below a taste of it :
http://www.codeplex.com/linq2wmi
A far more clear solution is to use the command netsh to change the IP (or setting it back to DHCP)
Where "Local Area Connection" is the name of the network adapter. You could find it in the windows Network Connections, sometimes it is simply named "Ethernet".
Here are two methods to set the IP and also to set the IP back to DHCP "Obtain an IP address automatically"
- 1 This doesn't answer the question... this is just abuse netsh and external processes without any error handling to probably get what you were aiming for... doing it natively is a bit harder but worth the extra effort. – cb88 Sep 17, 2019 at 16:59
A slightly more concise example that builds on top of the other answers here. I leveraged the code generation that is shipped with Visual Studio to remove most of the extra invocation code and replaced it with typed objects instead.
Full source: https://github.com/sverrirs/DnsHelper/blob/master/src/DnsHelperUI/NetworkManagement.cs
The existing answers have quite broken code. The DNS method does not work at all. Here is code that I used to configure my NIC:

This maybe more clear:
Not the answer you're looking for? Browse other questions tagged c# .net configuration networking or ask your own question .
- The Overflow Blog
- How Intuit democratizes AI development across teams through reusability sponsored post
- The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie...
- Featured on Meta
- We've added a "Necessary cookies only" option to the cookie consent popup
- Launching the CI/CD and R Collectives and community editing features for...
- Staging Ground Beta 1 Recap, and Reviewers needed for Beta 2
- The [amazon] tag is being burninated
- Temporary policy: ChatGPT is banned
Hot Network Questions
- Is there a single-word adjective for "having exceptionally strong moral principles"?
- How do you get out of a corner when plotting yourself into a corner
- How to match a specific column position till the end of line?
- My code is GPL licensed, can I issue a license to have my code be distributed in a specific MIT licensed project?
- Euler: “A baby on his lap, a cat on his back — that’s how he wrote his immortal works” (origin?)
- Are there tables of wastage rates for different fruit and veg?
- Theoretically Correct vs Practical Notation
- Disconnect between goals and daily tasks...Is it me, or the industry?
- What is the point of Thrower's Bandolier?
- Follow Up: struct sockaddr storage initialization by network format-string
- Using indicator constraint with two variables
- Is there a proper earth ground point in this switch box?
- What Is the Difference Between 'Man' And 'Son of Man' in Num 23:19?
- A-Z related to countries
- Counting Letters in a String
- Tips for golfing in SVG
- Can airtags be tracked from an iMac desktop, with no iPhone?
- Largest Binary Area
- Does Counterspell prevent from any further spells being cast on a given turn?
- Describing the homotopy explicitly.
- Can archive.org's Wayback Machine ignore some query terms?
- Why are Suriname, Belize, and Guinea-Bissau classified as "Small Island Developing States"?
- Did any DOS compatibility layers exist for any UNIX-like systems before DOS started to become outmoded?
- Calculating probabilities from d6 dice pool (Degenesis rules for botches and triggers)
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .
How to Change IP Address in Command Prompt (Renew IP)
Steps to change ip address in command prompt.


IMAGES
VIDEO
COMMENTS
netsh interface ipv4 set address name="Wi-Fi" static 192.168.3.8 255.255.255.0 192.168.3.1 where the info is replaced by whatever you want to use. In our example, the command does the following: Uses the interface name “Wi-Fi” Sets the IP address to 192.168.3.1 Sets the subnet mask to 255.255.255.0 Sets the default gateway to 192.168.3.1
Here’s how to configure a static IP address: netsh interface ip set address "connection name" static 192.168.0.101 255.255.255.0 192.168.0.1 NOTE: The default connection names are Local Area Connection for wired adapters and Wireless Network Connection for Wi-Fi adapters. The IP address order: client IP, subnet mask, and gateway IP.
A far more clear solution is to use the command netsh to change the IP (or setting it back to DHCP) netsh interface ip set address "Local Area Connection" static 192.168.0.10 255.255.255.0 Where "Local Area Connection" is the name of the network adapter. You could find it in the windows Network Connections, sometimes it is simply named "Ethernet".
First, press the Windows key to open the Start menu. Now, type “ Command Prompt ” in the search bar. Right-click on the Command Prompt and select the “ Run as administrator ” option. Execute the below command to get the network interface name. netsh interface ipv4 show config