PortGate

Resources · Port reference · port 11211

Port 11211 (Memcached): what it is and how to secure it

Memcached on port 11211 has no login. A public 11211 leaks cached data, and open UDP 11211 has been used for record DDoS attacks.

Check command

sudo ss -tulpn | grep 11211

Copied.

Port 11211 is Memcached, which has no authentication by default. Bind it to 127.0.0.1 and turn UDP off. An open Memcached leaks whatever your app caches, and open UDP 11211 was used for some of the largest DDoS attacks ever recorded.

What port 11211 is for

Memcached is a simple in-memory cache. PHP, Python and Ruby apps use it for sessions, page fragments and query results. Only your app should talk to it, usually on the same server.

Why an open Memcached is dangerous

  • Data: anyone can read and overwrite cached values, which can include sessions and user data.
  • DDoS: a tiny UDP request to 11211 can make Memcached send back a reply tens of thousands of times larger. Attackers fake the victim's address, so your server joins the attack. In 2018 this produced attacks of more than 1 Tbps.

Since version 1.5.6, Memcached ships with UDP off, but older packages and custom options still enable it.

Check yours

sudo ss -tulpn | grep 11211
grep -E "^-(l|U|p)" /etc/memcached.conf

Look for both tcp and udp lines. 127.0.0.1:11211 on TCP only is what you want. From another machine:

printf "stats\r\nquit\r\n" | nc -w 3 YOUR_SERVER_IP 11211 | head -3

Any STAT lines mean it is public.

Fix it

In /etc/memcached.conf on Debian and Ubuntu:

-l 127.0.0.1
-U 0

-l sets the listen address and -U 0 turns UDP off. Then:

sudo systemctl restart memcached
sudo ss -tulpn | grep 11211

For Docker, publish on loopback and turn UDP off:

services:
  memcached:
    image: memcached:1.6
    command: ["memcached", "-U", "0"]
    ports:
      - "127.0.0.1:11211:11211"

If other servers need the cache

Bind to the private network address instead of 127.0.0.1, and allow only your app servers' IPs. Memcached can also require logins, with SASL or, from 1.5.13, a simple auth file, but keep the network rules either way.

Common mistakes

  • -l 0.0.0.0 copied from a container guide onto a server with a public IP.
  • Fixing TCP but leaving UDP open. The DDoS problem is UDP.
  • Docker publishing 11211. UFW does not filter Docker-published ports.

FAQ

Does Memcached have a password? Only with SASL, which most installs do not use. Rely on the bind address.

My provider says my server is part of a DDoS. Is this why? If UDP 11211 is open, very likely. Apply the fix above right away.

How do I get warned? PortGate's Server Guard alerts when 11211 listens on a public address, over TCP or UDP.