Change IP Config Using Simple Batch Script

by Oscar

I have a two laptops and only one network port, although i can use wifi on both computers, I prefer to use cable whenever I can for faster internet speed. So when sharing internet through one laptop to the other i need to switch IP config settings, which is a pain (where I need to change IP address, subnet and default gateway in IPV4, local area connection adapter).

Some of the links on this page are affiliate links. I receive a commission (at no extra cost to you) if you make a purchase after clicking on one of these affiliate links. This helps support the free content for the community on this website. Please read our Affiliate Link Policy for more information.

Therefore I came up with this simple script for easier access to the IP config settings. There are two main things it can do: 1. set static IP address; 2. set auto IP config (dhcp – dynamic ip address).

@echo off echo Notice: Make sure you are running this script as Admin, Otherwise it won't work! (right click on the script, click "Run As Administrator") echo Choose: echo [A] Set Static IP echo [B] Set DHCP echo. :choice SET /P C=[A,B]? for %%? in (A) do if /I "%C%"=="%%?" goto A for %%? in (B) do if /I "%C%"=="%%?" goto B goto choice :A @echo off echo "Please enter Static IP Address Information" echo "Static IP Address:" set /p IP_Addr= echo "Subnet Mask:" set /p Sub_Mask= echo "Default Gateway:" set /p D_Gate= echo "Setting Static IP Information" netsh interface ip set address name="Local Area Connection" static %IP_Addr% %Sub_Mask% %D_Gate% netsh int ip show config pause goto end :B @ECHO OFF ECHO Resetting IP Address and Subnet Mask For DHCP netsh int ip set address name = "Local Area Connection" source = dhcp ipconfig /renew ECHO Here are the new settings for %computername%: netsh int ip show config pause goto end :end

Don’t forget you have to run this script as Administrator, otherwise it won’t work.

Leave a Comment

By using this form, you agree with the storage and handling of your data by this website. Note that all comments are held for moderation before appearing.


Odd Bjerga 11th April 2022 - 2:41 am

How, by default, user without administrator password to change DHCP network connection?

I manage many remote Windows 7 and Windows 10 PCs that are logged on as standard users, where I log on to these via remote control program for necessary maintenance. The PCs are set up with a static IP address, and the users do not have access to the administrator password.
Sometimes I lose contact with some of the PCs, and to restore the connection, the network connection on the PC has to be changed to DHCP.
Is there a method where users can change this, without having to enter the administrator password, e.g. by running a script that changes the network connection to DHCP, or by giving the default user administrator permission for the required functions?

Brian 17th April 2014 - 4:18 pm

What about for setting DNS?

Ricardo Calles 21st April 2015 - 12:08 pm

Could you be more lazy?
The code is very elegant.
It is your responsibility to go one step forward.

Bryan Ringrose 12th June 2015 - 5:02 pm

Could you be more arrogant!?
The code is not that elegant and has been passed on from site to site. Yes this is a very useful script that someone has posted on a knowledge sharing website so IT IS OK (without being perceived as lazy) to ask about DNS just like others have asked on this very script. Please do ask questions, rude comments are not needed.

Jaimie 21st March 2014 - 10:24 pm

Nice post. I was checking continuously this blog
and I am impressed! Very useful info specially
the last part :) I care for such info much. I was
seeking this particular information for a long time.
Thank you and best of luck.