9
2
Split question: this other one here is for Windows.
Linux: Fastest way to disable internet (keeping LAN) from command line?
I think the easiest way to deactivate internet (not LAN) in Linux is to remove the default gateway, so, assuming LAN is 10.0.2.0/24 and gateway is 10.0.2.1 :
sudo /sbin/route del default gw 10.0.2.1
To reactivate internet:
sudo /sbin/route add default gw 10.0.2.1
But, even when this a simple line, it requires to discover the default gateway IP first:
sudo /sbin/route
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
, maybe?) operations to filter and detect the exact gateway IP number (it could be 10.0.2.1, 127.0.0.1, 127.0.50.1, 192.168.0.1 ... etc), unless I achieve to find a simpler command line.
Any ideas, please?
2Do you need to disconnect from internet (no internet access, but maintain LAN connection), or completely disconnected from the network? – Darius – 2014-02-03T22:28:00.780
Read first line: «deactivate internet (not LAN)». Anyway, I have edited the post to be clearer. – Sopalajo de Arrierez – 2014-02-03T22:36:43.787