I'm looking to block internet access on my Linux laptop after a certain hour. Initially I was going to try chomper paired with a chron job to do the trick, but ran into a bug.

In particular I want to shut down my internet access every night (i.e 1am). Allowing certain sites is a bonus, but not a necessity.

  • 2
    First place I'd look would be my router. Often they provide some "child protection" and similar restrictions, with per-client schedules/filters. If you haven't that, a rough idea would be a cron-job switching the default route to localhost at your "shutdown time", and restore the correct one when you want your connection back. Far from the flexibility Chomper gives you, though.
    – Izzy
    Commented Sep 24, 2018 at 17:18
  • I do not have access to the router system in my building.
    – dluxcru
    Commented Sep 24, 2018 at 23:38
  • Honestly, even chron job to shut off the wifi on my computer would be a pretty good start here.
    – dluxcru
    Commented Sep 24, 2018 at 23:38
  • 1
    man ifup :) So if your WiFi interface is named wlan0 (check output of ifconfig to find out), ifdown wlan0 should bring it down and ifup wlan0 bring it up again. Put each in its resp. cron job (after verifying they do their job), and you're done. Must be run as root, of course.
    – Izzy
    Commented Sep 25, 2018 at 9:11
  • @Izzy can you write out a complete example of this as answer, including some detail on chron jobs (I know they're used to automate scheduled tasks but am honestly not familar with the commands that are used to manage them)? If well done that would be an acceptable answer.
    – dluxcru
    Commented Oct 2, 2018 at 3:51

1 Answer 1


The software you need for the "basic variant" (as you wrote: "chron job to shut off the wifi on my computer would be a pretty good start") is already available on your Linux machine:

  • Cron for the timing
  • ifconfig to identify your WiFi interface
  • ifup and ifdown to connect/disconnect the interface

First step: find out what your WiFi interface is named. For that, simply run ifconfig (or ifconfig -a for more details). Not having WiFi on my Linux machine, I don't know what the name might be – for this example, let's assume it is wifi1.

Next, adjust your Cron config. If it were a hourly/daily/weekly/monthly task, that would be as easy as placing scripts into /etc/cron.(hourly|daily|weekly|monthly) – but we need a single action at a given time. So we place a new file into /etc/cron.d, and call it e.g. wifitoggle. It would go a bit far for this site to include a cron tutorial – but you can find one at help.ubuntu.com. Good idea to familiarize yourself with it, comes in handy the next time. For this time and lazyness, consider using a crontab generator. Add the generated lines (2, one for disconnecting at 1am (ifdown wifi1), and another for re-establishing the connection (ifup wifi1) at 7am or whatever) to the /etc/cron.d/wifitoggle file and save it – you're done. Cron automatically detects new files in its vicinity or changes to them, and updates its schedules accordingly.

  • Still making some tweaks to make this work. So far I've found that I need to use sudo ifconfig wlan0 up and sudo ifconfig wlan0 down, respectively to get the underlying commands to work.
    – dluxcru
    Commented Oct 30, 2018 at 0:36
  • Ugh, sure. I was thinking of a "system cron job" here, as the network connection isn't user-based you certainly need root powers for that.
    – Izzy
    Commented Oct 30, 2018 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.