Geeky Fun: Knockd
I ran across this crazy application yesterday named knockd. Knockd is a daemon that listens for a specified series of ‘knocks’ on specified ports and then performs a specified action. Do I win an award for using the word ’specified’ three times in one sentence?
This may not be a new Linux user topic per se, but it has so much potential that I wanted to make sure I mentioned it.
In this example, Marius uses knockd to modify his iptables when he pings ports 7000, 8000, and 9000 in sequence. The modification involves adding the IP address that the pings came from to allow that IP to SSH into the system. When he’s done, he pings the ports in reverse order and knockd then removes that IP’s access. This allows him to keep his box secure by not allowing anyone except a single internal IP to SSH in except for the brief period of time when he uses knockd to change that. Bloody brilliant.
I’ve not used knockd yet although I’m really racking my brains to come up with a good excuse to try it out.

















Another way to do it is to open the port, specify a short timeout (probably 10-60 seconds), and then automatically close the port (using start_command, cmd_timeout, and stop_command instead of just command).