Looking to block all network traffic anytime I am away from the computer. I tried putting the iMac to sleep every time I step away and changed the sleep mode to hibernation as well changed energy saving settings to disable network traffic and Wake on LAN, and Powernap is disabled, but my router reports that my iMac still is doing network communication after I put it to sleep.

I am looking to prevent this.

Any script I can run when I lock the computer?


It seems I can run this command as a script:

/usr/libexec/ApplicationFirewall/socketfilterfw --setblockall on

The problem is it won't work unless I sudo it, and I don't want to have to put in a password every time I lock the screen so this script runs.

Is there any way around this short of removing the need to provide a password to sudo?

  • It could be just basic traffic to the router and the other devices on the network. For example the router knows you are a part of the local network so it will periodically sends out a “knock knock” to see if anybody is there... that would look like a lot of packets but small amount of data. Can you see if the router is logging any activity outside the local network?
    – Theologin
    Jul 31, 2019 at 20:02
  • What Mac model and what OS? Have you turned off Power Nap? Is it possible that the router is supplying accurate information. Also, assuming battery life is minimally affected, why is this a problem for you?
    – benwiggy
    Jul 31, 2019 at 20:17
  • @ankiiiiiii In this case no. The answers shoulds be edited into the question
    – mmmmmm
    Aug 8, 2019 at 12:00
  • 1
    Launch console, leave it open then put your computer to sleep. After a few, wake her back up and take a look at the logs. Maybe you can gather more information that can help other ID why the computer is utilizing the network traffic when told not to.
    – Theologin
    Aug 8, 2019 at 17:00
  • 1
    Also look Into ifconfig, you can turn off interfaces. You can download wireshark (network packet inspector application). You could either run it on the same machine or run it from another machine on the same network in promiscuous mode. You may want to take a look at your loopback too. Loopback is like a virtual interface that makes a internal network for your system for things like applications communicating to each other, ect.
    – Theologin
    Aug 8, 2019 at 17:05

1 Answer 1


This is almost as fast as having a lock script. Basically, just turn your ethernet interface(s) off/on.

  1. in a terminal run 'sudo -s'
  2. before locking run 'ifconfig en1 down'
  3. after unlocking run 'ifconfig en1 up'
  4. leave the terminal open but just minimize it for later use

    • if you don't know which is your active interface, run ifconfig and look for the entry with an IP Address. In the example above, my WiFi interface is en1. ** if you have multiple interfaces just concatenate the command: 'ifconfig en1 down && ifconfig en2 down' …&etc as needed.
  • Thanks! it is a decent approach but sometimes I just walk away from my desktop so I need a way to achieve this for it to happen automatically.
    – Max S
    Aug 13, 2019 at 16:50

You must log in to answer this question.

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