I want to test a fallback strategy for my memcached driver (in case port is protected by firewall). How can I deny access to a specific port, on 127.0.0.1?
Example for Mac OS X 10.6 (Snow Leopard)
to deny connections to localhost, port SSH (= 22, read from
You can use
OS X 10.7 "Lion" and later use the OpenBSD PF (Packet Filter). A pseudo-device called
To filter port 1234 on the loopback interface you can use a rule like this:
This rules blocks all inbound/outbound traffic on
The command to load the rule in PF is:
If there's no error message, you can apply the rule as follows (only difference: there's no
If you wish you can list the rules and check it has been added properly:
When you're done, load the original set of rules like this:
(I've tested the whole procedure on OS X 10.8.2 and worked flawlessly.)
You can find more information in this excellent introduction: http://nomoa.com/bsd/gateway/pf/valid/pfctl.html.
@jaume If there is no pf.cong file and then I run your command suggestion,
is there a similar command I could use to also delete the entry ?
I am basically trying to block the route to the NTP server.