23

I'm trying to use memcached from a different machine (which has access to my server), but I can't figure out how.

on the memcached machine I can test the connection by running

telnet 127.0.0.1 port

And it works, but on the other machine it just keeps trying to connect

telnet machine_address port
Trying machine_address...

I'm not sure if I should set up something else to get it working. I know the port is working and accessible because if I try to run other services on it, they works.

Os is ubuntu

1
  • I am having this same problem with my virtual machines, telnet returns "connection refused". Local telnet in the memcache machine does work. Added an explicit rule to the iptables to allow the 11211 port, no dice, added a rule in the router to allow the port, no dice...
    – Purefan
    Oct 8, 2011 at 15:55

3 Answers 3

27

In /etc/memcached.conf:

# 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.
-l 127.0.0.1

Change that to

-l 0.0.0.0

and restart memcached.

6
  • That didn't work unfortunately. Jun 1, 2011 at 8:52
  • 1
    Check the output of netstat -ln4t then to see if it's listening on 127.0.0.1:11211 or 0.0.0.0:11211.
    – Majenko
    Jun 1, 2011 at 12:07
  • the output is 0.0.0.0:* Jun 1, 2011 at 14:01
  • Its embarrassing how long it took me to figure this out. Thanks @Majenko
    – Ascherer
    Oct 23, 2013 at 1:19
  • @Majenko You are talking about Local Address? Dec 15, 2016 at 11:20
3

Edit the -l line in /etc/memcached.conf. This is where your startup options are stored.

The following line will allow memcached to listen on all interfaces:

sudo sed 's/-l/#-l/' /etc/memcached.conf && sudo service memcached restart
0

There are two basic possibilities:

  • You've set your memcached instance to listen only on local loopback interface -- you can check this in netstat -l output.
  • You've got your iptables firewall set to reject all incoming connections, except those that are explicitly allowed.
1
  • I see the port allowed on both nestat and iptables. In ip tables it reads tcp dpt:11211 Jun 1, 2011 at 8:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .