I'd like to block use of the internet via my laptop's wifi network adapter while allowing LAN traffic to continue, using the command line so that it can be scripted.
To do that, I've tried adding a firewall rule that restricts traffic to the default gateway, as described here.
netsh advfirewall firewall add rule name="Block default gateway" dir=out action=block remoteip=192.168.179.1
When I do that, loading websites not recently visited in new tabs in the browser fails as you'd expect. But reloading tabs that had previously finished loading succeeds, and pinging a well known address like Google by using ping www.google.com at the command line is also successful.
If I then try to load www.google.com in a new tab in the browser it fails, and then after that if I try again to ping www.google.com at the command line that also fails.
It is as though not all requests are being sent via the default gateway, and are cached somewhere for a while.
To try to address that, I've tried flushing the route table with the following command, as described here.
netsh interface ip delete destinationcache
However, it doesn't seem to solve the problem.
How can I force the firewall rule to have an immediate effect even on open browser tabs or when connecting to addresses that have recently been visited?
Update: Please note that removing the default gateway using the route command does not work. The gateway is restored by the OS or something else that is running. (Details in comments on the related answer below.)