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).

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 
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 

@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 
goto end

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

goto 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.


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.