Split question: this other one here is for Linux.

I think the easiest way to deactivate internet (not LAN) in Windows command-line is to remove the default gateway, so, assuming LAN is and gateway is :

`route delete mask`  

To reactivate internet:

`route add mask`

But, even when this a simple line, it requires to discover the default gateway IP first:

  • In Windows:

    route print

I am going to build some general purpose shell scripts that need to enable/disable internet(but keep LAN working), so it seems I am going to need some grep equivalent operations to filter and detect the exact gateway IP number (it could be,,, ... etc), unless I achieve to find a simpler command line.
Any ideas, please?

  • EDIT: Some people reports that gateway deletion in Windows could also be done like this:

route delete

So, apparently, there would be no problem in modifying the deletion script made by @and31415 .

  • try to omit gateway - it should work so: route delete mask
    – MolbOrg
    Commented Apr 22, 2014 at 10:09
  • @MolbOrg, it seems there is no need for netmask specification. I have tested it with Windows XP SP3 and Windows 7 SP1. Commented Apr 22, 2014 at 10:29

1 Answer 1


Batch scripts

Similar to @John1024's approach, here's how you can do it in Windows:


@echo off
cd /d "%~dp0"

REM retrieve the current gateway
set dest=
for /f "tokens=2,3" %%A in ('"route print %dest% | findstr /c:"%dest%" "') do (

REM save the IP and delete the gateway
echo %%A %%B>%dest%.txt
route delete %dest% >nul
exit /b


@echo off
cd /d "%~dp0"

REM ensure the settings file exists
set dest=
if not exist %dest%.txt exit /b 2

REM restore the default gateway
for /f "tokens=1,2" %%A in (%dest%.txt) do (route add %dest% mask %%A %%B >nul)
exit /b

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .