{"id":176,"date":"2011-12-21T12:14:35","date_gmt":"2011-12-21T18:14:35","guid":{"rendered":"http:\/\/csmartonline.com\/blog\/?p=176"},"modified":"2011-12-27T23:04:00","modified_gmt":"2011-12-28T05:04:00","slug":"install-knockd-for-clearos","status":"publish","type":"post","link":"http:\/\/csmartonline.com\/blog\/2011\/12\/21\/install-knockd-for-clearos\/","title":{"rendered":"Installing knockd for ClearOS"},"content":{"rendered":"<p>Installing knockd for ClearOS is anything but, trivial if you are not familiar with the platform. I use Ubuntu and was having a hard time with getting knockd to work on ClearOS. These are my adventures (actually fairly simple as it turns out)&#8230;<\/p>\n<p>To install knockd on ClearOS, we first need to install gcc, rpm-build, and libpcap-devel:<\/p>\n<pre class=\"snippet-code\">\r\n#yum install gcc rpm-build libpcap-devel\r\n<\/pre>\n<p>We then need to fetch the source RPM package for knockd:<\/p>\n<pre class=\"snippet-code\">\r\n#wget http:\/\/www.invoca.ch\/pub\/packages\/knock\/RPMS\/ils-5\/SRPMS\/knock-0.5-7.el5.src.rpm\r\n<\/pre>\n<p>Now build the source RPM package:<\/p>\n<pre class=\"snippet-code\">\r\n#rpmbuild --rebuild knock-0.5-7.el5.src.rpm\r\n<\/pre>\n<p>Finally, install the newly created RPM package which should be located at &#8216;<strong>\/usr\/src\/redhat\/RPMS\/i386\/<\/strong>&#8216;:<\/p>\n<pre class=\"snippet-code\">\r\n#cd \/usr\/src\/redhat\/RPMS\/i386\/\r\n#rpm -ivh knock-server-0.5-7.i386.rpm\r\n<\/pre>\n<p>We should now have knockd:<\/p>\n<pre class=\"snippet-code\">\r\n#knockd --help\r\nusage: knockd [options]\r\noptions:\r\n-i, --interface &lt;int&gt;\u00a0 network interface to listen on (default \"eth0\")\r\n-d, --daemon\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 run as a daemon\r\n-c, --config &lt;file&gt;\u00a0\u00a0\u00a0 use an alternate config file\r\n-D, --debug\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 output debug messages\r\n-l, --lookup\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 lookup DNS names (may be a security risk)\r\n-v, --verbose\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 be verbose\r\n-V, --version\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 display version\r\n-h, --help\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this help\r\n<\/pre>\n<p>We now need to setup our &#8216;<strong>knockd.conf<\/strong>&#8216; file:<\/p>\n<pre class=\"snippet-code\">\r\n#vi \/etc\/knockd.conf\r\n<\/pre>\n<p>Mine looks like this after playing around with iptables and customizing it to my need:<\/p>\n<pre class=\"snippet-code\">\r\n[options]\r\nlogfile = \/var\/log\/knockd.log\r\ninterface = eth0\r\n\r\n[opencloseVNC]\r\n\r\nsequence\u00a0\u00a0\u00a0\u00a0\u00a0 = 8181:tcp,5901:tcp,8181:tcp,5901:tcp\r\nseq_timeout\u00a0\u00a0 = 15\r\nstart_command = \/sbin\/iptables -A FORWARD -o eth1 -p tcp --dport 5901 -j ACCEPT -d 192.168.2.24 -s %IP% &amp;&amp; iptables -t nat -A PREROUTING -p tcp --dport 5901 -j DNAT --to-destination 192.168.2.24:5901 &amp;&amp; iptables -t nat -A POSTROUTING -p tcp --dport 5901 -j SNAT --to-source 192.168.2.1 -d 192.168.2.24 -s 192.168.2.0\/24\r\ncmd_timeout\u00a0\u00a0 = 10\r\nstop_command\u00a0 = \/sbin\/iptables -D FORWARD -o eth1 -p tcp --dport 5901 -j ACCEPT -d 192.168.2.24 -s %IP% &amp;&amp; iptables -t nat -D PREROUTING -p tcp --dport 5901 -j DNAT --to-destination 192.168.2.24:5901 &amp;&amp; iptables -t nat -D POSTROUTING -p tcp --dport 5901 -j SNAT --to-source 192.168.2.1 -d 192.168.2.24 -s 192.168.2.0\/24\r\n<\/pre>\n<p>You&#8217;ll of course need to customize it to your needs. That however, is outside the scope of this article. You can refer to here for help: <a href=\"http:\/\/www.zeroflux.org\/projects\/knock\" target=\"_blank\">http:\/\/www.zeroflux.org\/projects\/knock<\/a><\/p>\n<p>At this point, you should run &#8216;<strong>knockd<\/strong>&#8216; and test that your configuration works as intended.<\/p>\n<p id=\"service\">If you would like to add knockd to the list on the services page within ClearOS, you will need to add an entry to the &#8216;<strong>Daemon.inc.php<\/strong>&#8216; file:<\/p>\n<pre class=\"snippet-code\">\r\n#vi \/var\/webconfig\/api\/Daemon.inc.php\r\n<\/pre>\n<p>Add the following line into the array at the bottom:<\/p>\n<pre class=\"snippet-code\">\r\n\"knockd\"\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 =&gt; array(\"knock-server-0.5-7\",\u00a0\u00a0\u00a0 \"knockd\",\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"yes\",\u00a0 \"knockd\",\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \"no\",\u00a0 null),\r\n<\/pre>\n<p>That&#8217;s it! You&#8217;re done! Congratulations! You have successfully installed knockd for ClearOS!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installing knockd for ClearOS is anything but, trivial if you are not familiar with the platform. I use Ubuntu and was having a hard time with getting knockd to work on ClearOS. These are my adventures (actually fairly simple as &hellip;<\/p>\n<p class=\"read-more\"><a href=\"http:\/\/csmartonline.com\/blog\/2011\/12\/21\/install-knockd-for-clearos\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[45,60,65,66,64,59,41,61,63,62],"class_list":["post-176","post","type-post","status-publish","format-standard","hentry","category-tiptrick","tag-clearos","tag-daemon","tag-firewall","tag-forward-port","tag-iptables","tag-knockd","tag-port","tag-rpm","tag-source","tag-source-rpm"],"_links":{"self":[{"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/posts\/176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/comments?post=176"}],"version-history":[{"count":11,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":229,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/posts\/176\/revisions\/229"}],"wp:attachment":[{"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/media?parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/categories?post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/csmartonline.com\/blog\/wp-json\/wp\/v2\/tags?post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}