Take the 2-minute tour ×

Editing /etc/hosts works to easily block/unblock sites, but if you already have a browser open, it doesn't work until the browser cache is flushed.

Is there any simple way on OSX to block connections to certain hosts, preferably without 3rd party software? I imagine Little Snitch does what I need behind the scenes, if anyone understands how that works.

share|improve this question

migrated from stackoverflow.com May 11 '13 at 3:32

This question came from our site for professional and enthusiast programmers.

you specify without 3rd party software, but it would be criminal not to mention that Little Snitch does what you want brilliantly! And should be a standard install on every OSX machine connected to the internet! –  Jarrod Roberson May 11 '13 at 3:43
@JarrodRoberson Love little snitch! I'm looking to develop a piece of software that can block sites on it's own, similar functionality, any idea how LS works under the hood?. –  Alex Marchant May 11 '13 at 4:14

1 Answer 1

up vote 2 down vote accepted

There are 3 ways to do this on Mac OS X without requiring you to do a lot more.

  1. You have already mentioned the first way - using /etc/hosts.
  2. You have also ruled out using the second way - using browser plugins.
  3. The 3rd way is to use the "Parental Controls" feature under System Preferences.

There is a 4th way - if you are talking about writing code and implementing your own script or your own custom app.

If you are talking about "under the hood" level implementation - i.e. you want to implement a custom application of your own (similar to Little Snitch), then you should get yourself familiar with the concept of iptables (linux systems routinely use this to control access rights to specific hosts and ports).

In Mac OS (which essentially is FreeBSD under the hood), the equivalent is ipfw (IP Firewall) and for Mac OS 10.7 onwards, ipfw has been deprecated in favour of pf (Packet Filter).

Reference article which you can refer to: http://ikawnoclast.com/security/mac-os-x-pf-firewall-avoiding-known-bad-guys/

share|improve this answer
Thanks for adding to your answer, that's what I was looking for. –  Alex Marchant May 11 '13 at 7:35

Your Answer


