My memcache server is up and running on Server A.

service memcached start
memcached -d -u nobody -m 512 -p 11211
chkconfig --list | grep memcache
chkconfig memcached on

I also have a web application on Server B (different IP). How can I configure Server A for memcache to allow incoming connections from Server B?


By default memcached only serves the localhost as it otherwise has no protection from the wider network / internet and is insecure. As you see in the output you posted it's currently only serving connections over

memcached -d -u nobody -m 512 -p 11211

So, you need to edit the configuration file and give it the IP address of the network interface that you want to serve. To do this head over to the directory where the config file is located. On ubuntu, this is:

cd /etc/

Then open the config file in your editor of choice:

sudo nano memcached.conf

Then scrol down until you find this:

# Specify which IP address to listen on. The default is to listen on all IP addresses
# This parameter is one of the only security measures that memcached has, so make sure
# it's listening on a firewalled interface.

Now just replace with the IP of your network interface and save.

Now you'll need to restart the memcached server:

sudo service memcached restart

Memcached will now be serving only requests received via that IP/network interface. You can test this with the following command:

ps aux | grep memcached

If everything went ok, you should see the IP you entered in the config rather than the localhost.

|improve this answer|||||
  • Thanks for the help! And if I want to include both and the new IP address can I just blank-space separate them? – Andres SK Nov 20 '17 at 17:33
  • To be honest, I'm not sure. I tried a comma and space (, ) between them and whilst everything ran smoothly I was only able to connect on the IP first in the list. I didn't get around to trying with just a space. I'd be keen to here if that works or not. – Phill Healey Nov 20 '17 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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