In Debian, I have installed memcached (using this guide) to lower the otherwise unmanageable load on mysql database. The database is on a separate server, and memcached and Varnish are on the front server. Is it a potential security hole to leave memcached unprotected by a firewall? If so, how should I secure it? The situation is especially worrisome,as I've received (unproved) reports of cookie thefts on the server. Thanks


Just block the memcached port in firewall and allow access only from the database server. This should give you some protection. Also you can bring up a SSL tunnel between the mysql and memcached server and make the memcached-mysql data flow through it only.

For the SSL tunnel you can use IPSEC, to set it up you can follow the tutorial at http://wiki.debian.org/IPsec or http://lartc.org/howto/lartc.ipsec.tunnel.html

For blocking the port for all ip's except one you can issue an iptables command like:

iptables -A INPUT -s -p tcp --destination-port 11211 -j ALLOW
iptables -A INPUT -s -p tcp --destination-port 11211 -j DROP


iptables -A INPUT -s ! -p tcp --destination-port 11211 -j DROP

Also as I understand your webserver and memcached server are on the same machine? If so then it is your webserver that will communicate with memcached rather then the mysql server. It will just either get the data from cache or if it's not present in the cache will get it from the mysql server. In this case it's just enough to bind memcached to localhost so only your webserver can access memcached using php, ruby, python or any other language code, this should as safe as it can be.

  • Will you please elaborate on how to do these, assuming that my web server's IP is at and database servers' Ip Thanks – alfish Sep 4 '12 at 21:44
  • I've edited my answer with more info. – Logic Wreck Sep 4 '12 at 21:57
  • As you notices, memcached is on the webserver, so I think you need to edit the iptables rules accrodingly. – alfish Sep 4 '12 at 22:00
  • Well - if it's on the webserver then probably there is no need to do that, it's better to just bind it to localhost on the webserver since it will be the webserver which will use it directly and not mysql. This will really be the safest option. – Logic Wreck Sep 4 '12 at 22:04
  • So, just to clarify, to bind memcached to the localhost. I need to put instead of in the rules above. Correct? – alfish Sep 4 '12 at 22:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.