Skip to content

maxuru ~ % cat memcached/bind-to-localhost

Bind Memcached to localhost

Severity: criticalApplies to: Memcached 1.5.xApplies to: Memcached 1.6.x
The fix/etc/memcached.conf
Terminal window
-l 127.0.0.1
-l ::1
Terminal window
sudo systemctl restart memcached

On RHEL and Fedora the same setting goes in OPTIONS in /etc/sysconfig/memcached; in a container it goes in the command:.

Because in memcached’s default build there is nothing behind it. No password, no ACL, no protected mode. A TCP connection to 11211 is a complete grant:

Terminal window
# From anywhere that can reach the port
printf 'stats items\r\n' | nc target 11211 # what keys exist
printf 'get session:abc123\r\n' | nc target 11211 # read a value
printf 'flush_all\r\n' | nc target 11211 # drop the entire cache

None of that requires a credential, because there is no credential to require. Authentication is available — see require authentication — but it is off by default and, for SASL, needs a binary built for it. Until then the listening address is the access control.

The upstream default is INADDR_ANY, which is every interface the host has. The help text says so plainly: -l, --listen=<addr> interface to listen on (default: INADDR_ANY).

If the only clients are on the same host — the common case for a single-server application — loopback is correct and complete:

Terminal window
-l 127.0.0.1
-l ::1

Include the IPv6 line. A host that resolves localhost to ::1 will fail to connect if only the IPv4 loopback is bound, and the usual reaction to that failure is to widen the binding rather than add one line. The Debian package ships both for this reason.

If clients are on other hosts, bind the specific private address — never 0.0.0.0:

Terminal window
-l 10.0.1.20

Binding a private address is not a substitute for a firewall. It means the daemon ignores traffic arriving on other interfaces; it does not stop anything that can already route to 10.0.1.20. On a cloud network where the whole VPC can reach that address, you still need a security group.

If every client is genuinely local, memcached can skip the network entirely:

Terminal window
-s /var/run/memcached/memcached.sock
-a 0770

The help text is explicit that -s disables network support — there is no port at all, and access is decided by filesystem permissions with -a as the octal mask. This is the strongest available answer for a single-host deployment, and it removes the exposure rather than narrowing it.

It rules out remote clients completely, and not every client library speaks Unix sockets, so check yours first.