3

I need a way to disable and then enable internet access via command line while still remaining connected to wifi.

4
  • Which network do you mean? Your LAN?
    – A.B.
    Aug 26, 2015 at 16:30
  • any kind of internet access, I would like to restrict my ability to use the internet between the hours of 1pm - 5pm. While remaining connected via wifi. (the reason for this is that connecting to my router is usually a bit troublesome but the connection is good if I remain connected) Aug 26, 2015 at 16:32
  • Hnn, pull the cable from the wall?
    – A.B.
    Aug 26, 2015 at 16:37
  • Nice idea, but I don't think there is a terminal command for this. Aug 26, 2015 at 16:38

3 Answers 3

10

Removing your default gateway should do the trick, you'll still be able to reach everything in your subnet, but not outside of it. IIRC this should work, cannot try it atm, replace the IP with your routers IP (in the same subnet):

 sudo route del default gw 192.168.1.1

Edit: To undo it, this should work:

 sudo route add default gw 192.168.1.1

To find your default gateways IP:

route -n|grep "^0.0.0.0"
4
  • Thanks for the response, this doesnt seem to be working: SIOCDELRT: No such process Aug 26, 2015 at 16:36
  • You'll need to use the correct IP address. It should be in the second column of 'route -n|grep "^0.0.0.0"' Aug 26, 2015 at 16:41
  • i was copying the wrong ip Aug 26, 2015 at 16:42
  • @JakobLenfers mention in your answer that the IP should be in the same subset. Aug 26, 2015 at 16:44
2

Ubuntu now has an option under wifi network settings to limit connection use to local resources.

Settings > Wifi > Gear Icon > IPv4/IPv6

Check the tickbox next to use this connection only for resources on its network

settings dialog window

0

What you can try is rejecting all packets using firewall rule accept all packets within your network, when you want things normal just remove this firewall rule, make a script and run with cron. For more refer https://help.ubuntu.com/lts/serverguide/firewall.html, I have not tried this yet but will try it later. Let me know if you try it before me.

1
  • Have you tried it?
    – Daniel
    Apr 14, 2020 at 20:23

You must log in to answer this question.

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