How to set Static IP on Windows OS with Only One Line Command

One Line Command to Change the Static Ip Address on Windows 10

How to set Static IP on Windows OS with Only One Line Command

Home ยป Cookbook ยป How to set Static IP on Windows OS with Only One Line Command
If there was a way to run some commands and set up the static IP, wouldnโ€™t that be great! Hereโ€™s how to setup static IP of Windows using the command prompt.
Table of Contents

Recently, well, It was yesterday. So yesterday, in a project, I had 300 computers that were powered up for the first time, and one of my technicians and I needed to set IP addresses to all computers. Two people have 300 computers, so it makes 150 each. With the GUI, there are multiple steps. Go to start, then settings, network settings, blah blah blah. Oh my God. After a couple of computers, I just got frustrated and gave up. 

Now you can tell me, “Oh Roosho! Roosho!! Roosho!!! You claim to be the jack of all IT trades. You are just a fool. You could easily set up the DHCP server in the router, and the router should take care of everything”. Yes you are absolutely right. I thought of that. But, the project I was working on requires specific static IPs for particular computers.  

As a programmer and a Linux administrator, I prefer writing some commands over clicking Mouse. I am more comfortable with that. So if there is a way to run some commands in the command prompt and set up the static IP, that would be great. Here I am sharing how to set up the static IP of Windows 10 using the command prompt. 

To set a static IP address on Windows 10 using the Command Prompt, you can follow these steps:

Start MS-DOS as Administrator

To do this, open Run by pressing Windows+R. Write “cmd” and press Ctrl+Shift+Enter to open Command Prompt/MS-DOS as Administrator. Or, type “cmd” into the search bar on the taskbar, then right-click on the “Command Prompt” result and select “Run as administrator” from the menu. You can visit this article to know all the ways of how to start command prompt.

Run Command Prompt As Administrator
run command prompt as administrator

Select the Network Adapter and set Network Credentials

If you have only one NIC card the Network Adapter name will be Ethernet unless you have changed it. In the Command Prompt window, type the following command mentioning the Network Adapter Name, IP Address, subnet mask and default gateway and press Enter.

ShellScript
netsh interface ip set address name="<Interface Name>" static <IP Address> <Subnet Mask> <Default Gateway>

Command to Set Ip Address, Subnet Mask and Default Gateway
command to set ip address subnet mask and default gateway

Set DNS via Command (Bonus)

If you want to set the DNS Server addresses as well type the following command mentioning the Network Adapter Name, IP Address of the Preferred DNS Server.

ShellScript
netsh interface ip add dns "<Interface Name>" <DNS Address>

Set Primary or Preferred Dns Via Cmd
set primary or preferred dns via cmd

For Alternative DNS type the following

ShellScript
netsh interface ip add dns "<Interface Name>" <DNS Address> INDEX=2

Set Secondary or Alternative Dns Via Cmd
set secondary or alternative dns via cmd

Finally, Verify your Configuration

To verify that the IP address has been changed, you can use the following command

ShellScript
ipconfig /all

This command will show you all of the network adapter settings, including the new static IP address.

This is how I did it. But still I’m looking for a more easy way. If you have any you can share that with me.

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog.ย 
share this article.

ADVERTISEMENT

ADVERTISEMENT

Enjoying my articles?

Sign up to get new content delivered straight to your inbox.

Please enable JavaScript in your browser to complete this form.
Name