Batch file for configuring the ip address and removing it

1

My pc has a network configuration IP- 192.168.0.99 192.168.4.20 Mask- 255.255.255.0 255.255.255.0 Gateway- 192.168.0.1 192.168.4.1

I am connecting to the internet through the gateway 192.168.4.1. I want to disable the internet sometimes, so i need to remove the gateway 192.168.4.1, How can I achieve this through a batch file... I have created a batch file to add ip address to the interface.

netsh int ip set address "LAN" static 192.168.0.99 255.255.255.0 192.168.0.1 
netsh int ip add address "LAN" static 192.168.4.20 255.255.255.0 192.168.4.1
interface ip set dns "LAN" static 192.168.0.1
interface ip add dns "LAN" static 8.8.8.8

but this gives errors.If I use 'set' instead of ip 'add' in the second line, 192.168.0.99 is overwritten by 192.168.4.1.

Anbu

Posted 2014-10-17T03:52:30.747

Reputation: 875

possible duplicate of Windows command-line: Fastest way to disable internet (keeping LAN)?

– DavidPostill – 2014-10-17T07:05:34.507

Answers

0

If you want to disable Internet access while keeping local network access, you could just edit your routing table and remove your default route:

Within an elevate command prompt, these two commands should delete and recreate your default route:

  • route DELETE 0.0.0.0 MASK 0.0.0.0
  • route ADD 0.0.0.0 MASK 0.0.0.0 192.168.4.1

Note that the first command is temporary. Windows can recreate the default route after restarting the interface (or PC)

HSuke

Posted 2014-10-17T03:52:30.747

Reputation: 411