Monday 30 March 2020

How to Change LAN IP address and DNS Server by Batch file




Changing the TCP/IP settings via the GUI interface is very easy and simple. But
What happened if you are working with more than one network simultaneously? It will be very difficult to change IP Address and DNS server frequently via GUI Interface.
It is very easy to change IP Address and DNS server by Command Prompt using the built-in utility in Windows called batch file concept. 

What is Batch file??
·         Batch file is set of windows command which run one by one in command prompt.


If you run the above Batch file it will create a folder name of Example in D Drive

How to create a Batch file??
·         Open Run from windows start, type Notepad and press Enter
·         Type all windows command and save as Example.bat extension.  (Example is name of file,  you can choose any file name)


How to Run Batch file??
·         Right click on Batch file and select Run as Administrator.

Batch file for Network 1:
        “” netsh Interface ip set address name="wi-fi" static 192.168.1.10 255.255.255.0 192.168.1.1
            netsh interface ip set dns name="wi-fi" static 218.248.112.193
            netsh interface ip add dns name="wi-fi" 4.2.2.2 index=2  “”



In the example above, we changed the network properties for “Ethernet” to use a static IP address of 192.168.1.10,subnet mask  255.255.255.0 and a default gateway of 192.168.1.1.
DNS of network  is 218.248.112.193 and alternate DNS is 4.2.2.2
( wi-fi  is the name of Wireless LAN card. It is also applicable Wired LAN card)

After all command complete If you see network adapter settings via Control Panel, you’ll see that the values have been updated there in the GUI interface.
 

Batch file for Network 2:
“”  netsh Interface ip set address name="wi-fi" static 100.152.106.43 255.255.255.0 100.152.106.1
     netsh interface ip set dns name="wi-fi" static 100.152.255.13
     netsh interface ip add dns name="wi-fi" 100.199.222.19 index=2  “”
 

In the example above, we changed the network properties for “Ethernet” to use a static IP address of 100.152.106.43,subnet mask  255.255.255.0 and a default gateway of 100.152.100.1.
DNS of network  is 100.152.255.13 and alternate DNS is 100.152.255.19

After all command complete If you see network adapter settings via Control Panel, you’ll see that the values have been updated there in the GUI interface.
 Thank You 
Visit Again

No comments: