Memcached is built for speed inside a trusted network, and the project's own documentation is direct that it must not be exposed to the internet or to untrusted users, so its security depends on how you bind, filter and authenticate it. A memcached instance often holds session tokens, rendered pages, API responses and personal data copied from the database, and a reachable UDP listener can be abused to reflect traffic at third parties. Memcached gives operators clear controls for this: explicit listeners with -l, UDP off by default since 1.5.6, SASL on the binary protocol, token authentication on the text protocol, TLS since 1.5.13, and switches that turn off administrative commands. This guide covers how to combine them, how client credentials should be handled, what to monitor and how to roll changes out safely. It is for platform engineers, SREs and security architects running self-managed memcached, and it goes deeper than the general Database Security Guide.
This is an independent guide from NHI Mgmt Group, based on Memcached's public documentation as of November 2026. It is not sponsored or reviewed by the Memcached project. Product features change, so confirm settings against Memcached's current documentation.
Key takeaways
- Bind explicitly and keep 11211 private. Set
-lto127.0.0.1or a private address (the compiled default listens on all interfaces; Debian and Ubuntu packages bind to127.0.0.1), and firewall port 11211 from everything except application hosts. - Keep UDP off. UDP has been disabled by default since 1.5.6 (released 27 February 2018). Pin
-U 0in your configuration so an old template or package cannot turn it back on. - Add authentication as a second layer. Use SASL (
-S, binary protocol) or the text protocol auth file (-Y) so a client on the right network still needs a credential. - Encrypt with TLS where traffic crosses hosts. Build with
--enable-tls, start with-Z, setssl_min_versionto TLS 1.2 or 1.3, and usessl_verify_mode=2for client certificates. - Treat the cache as sensitive data. Separate instances per trust boundary, turn off
flush_alland dump commands where not needed, and monitor connections and auth failures.
How identity and access work in Memcached
Memcached's access model is deliberately simple. Network reachability is the first control, and authentication, when enabled, gates the whole connection: once a client authenticates, it can use the commands the server allows on that instance. In practice NHI Mgmt Group treats the instance as the unit of isolation. Plan one instance (or one port with its own credentials) per application or trust boundary rather than sharing a cache between services with different data sensitivity.
| Mechanism | Flag and requirement | Protocol | How it works |
|---|---|---|---|
| Network binding | -l / --listen, -p for the TCP port | All | Chooses the interfaces and ports memcached accepts connections on; supports several listeners |
| Unix domain socket | -s <file> with -a access mask (octal) | All | Local-only access controlled by file permissions; turns off TCP and UDP |
| SASL | -S, memcached 1.4.3+ built with --enable-sasl | Binary only | Requires SASL authentication before any command on a connection; users created with saslpasswd2 -a memcached -c <user> |
| Text protocol token auth | -Y <file>, marked experimental in the help text; file format user:pass per line | Text (ASCII) | The client sends a set whose payload is username password; STORED means success, CLIENT_ERROR means failure |
| TLS client certificates | -Z with ssl_verify_mode=2 and ssl_ca_cert | All over TLS | Only clients presenting a certificate from the trusted CA can connect |
Decision guidance: if your client library speaks the binary protocol, SASL is the established route. If you use the text or meta protocol, the -Y token file is the option the protocol documentation describes; check your client supports it and test it before relying on it. Where you already run an internal PKI, TLS with required client certificates gives strong mutual authentication and encryption together. Small deployments with the cache on the application host should simply use a Unix socket or loopback binding. The project notes that SASL helps but should not be your only defence, so in every case keep the network controls in place.
Admin roles and privileged access
In Memcached, administrative commands are available to any connected client when the server enables them, so access to the instance is the privileged path. Reduce that surface with startup flags and treat host access as the privileged path.
- Shutdown: the text protocol
shutdowncommand is off by default and only enabled with-A/--enable-shutdown. Leave it off and stop the service through your init system. - Flush:
flush_allinvalidates every item. Start with-F/--disable-flush-allif your application never needs it. - Dumping:
-X/--disable-dumpingturns offstats cachedump,stats detailandlru_crawler metadump, which can list keys held in the cache. - Watchers: the
watchcommand streams internal logs (fetchers, mutations, evictions, connevents and others). It is useful for operators and also reveals key names, so restrict who can reach the instance. - Host and configuration: the people who can edit
/etc/memcached.confor/etc/sysconfig/memcached, the SASL password database or the-Yfile control authentication. Manage them through your privileged access process. See the Privileged Access Management Guide. - Run as an unprivileged user: run the daemon under a dedicated service account, and keep the SASL password file and
-Yfile owned by and readable only by that account, as the SASL guide advises.
Integrations, API tokens and service accounts
Memcached's clients are almost always applications, so every memcached credential is a non-human identity.
- One credential per application: create a SASL user or a
-Yentry per service so you can rotate and revoke one client without touching others. Some client libraries append@hostnameto the SASL username, so check the exact name the server sees with verbose logging during setup. - Store credentials in a secrets manager: inject them into the application at runtime rather than committing them to configuration repositories or container images. See the Secrets Management Guide.
- Rotate safely: add the new credential alongside the old one, roll the application, confirm
auth_errorsstays flat, then remove the old entry and restart memcached in a planned window, remembering that a restart clears the cache. - Certificates: with TLS, keep server certificate and key paths stable and use the
refresh_certscommand to load renewed certificates without a restart; new connections use the new certificate. Thestatsoutput reportstime_since_server_cert_refresh, which you can alert on. - Cache content: session tokens, OAuth access tokens and API responses cached by the application are credentials in their own right. Set short expiry times, avoid caching long-lived secrets, and consider encrypting sensitive values in the application before storing them.
Logging and detection
Memcached keeps most of its operational evidence in counters rather than log files. Collect stats and stats settings on a schedule with your metrics agent, and send verbose output (-v) to the journal during troubleshooting only, since -vv prints client commands and responses.
| Counter or signal | Source | What it tells you |
|---|---|---|
auth_cmds, auth_errors | stats | Authentication volume and failures; a rising error count suggests guessing or a misconfigured client |
curr_connections, total_connections | stats | Unexpected clients or connection floods |
rejected_connections, listen_disabled_num | stats | Connection limit (-c, default 1024) reached |
udpport, auth_enabled_sasl, shutdown_command | stats settings | Drift from the baseline: UDP enabled, SASL off, shutdown on |
ssl_* settings, time_since_server_cert_refresh | stats settings, stats | TLS configuration and certificate age |
| Inbound 11211 TCP or UDP from outside the application network | Firewall or flow logs, external scans | Exposure, or attempted reflection abuse |
Two ATT&CK techniques frame the detection work: Reflection Amplification (T1498.002), where a reachable UDP listener is used against third parties, and Exploit Public-Facing Application (T1190) for any service reachable from the internet. On the cloud side, add a scheduled check that no security group or firewall rule allows 11211 from 0.0.0.0/0. For upstream reflection defences, see the DDoS Protection Guide.
Metrics that show the controls work:
- Instances reachable on 11211 from the internet, TCP or UDP (target: zero).
- Percentage of instances with
udpportset to 0 instats settings(target: 100%). - Percentage of instances requiring authentication or client certificates.
- Percentage of cross-host cache traffic carried over TLS.
- Days since each application credential was rotated, against policy.
Hardening baseline
Recommended startup flags
| Setting | Recommended value | Why |
|---|---|---|
-l / --listen | 127.0.0.1, a private address, or -s socket | Accept connections only where clients are |
-U | 0 | UDP off, explicitly; it has been off by default since 1.5.6 |
-S or -Y | Enabled | Authentication in addition to network controls |
-Z with -o ssl_chain_cert=...,ssl_key=... | Enabled for cross-host traffic | Encrypts cache data and credentials in transit (memcached 1.5.13+, OpenSSL 1.1.1+) |
ssl_min_version | TLS 1.2 or 1.3 (confirm the accepted values for your build with memcached -h) | Refuse older protocol versions |
ssl_verify_mode and ssl_ca_cert | 2 (Require) with your client CA | Mutual TLS; the default 0 does not check clients |
-A | Not set | Keeps the shutdown command off |
-F, -X | Set where the application allows | Turns off flush_all and key dumping |
-c, -m | Sized to the client fleet and memory budget | Limits connection and memory exhaustion |
If one listener must stay plain text, for example a local health check, the notls: prefix on -l marks just that interface; keep it on loopback. Apply vendor security updates promptly and follow the project's advisories.
Phased rollout
- Inventory: find every memcached process and container, its version and its startup flags. Run
stats settingson each to recordtcpport,udpport,auth_enabled_saslandmaxconns. - Close exposure: set
-l, set-U 0and apply firewall or security group rules for 11211. These changes rarely affect applications on the same network and remove the largest risk first. - Pilot authentication: enable SASL or
-Yon a staging instance, update one client, checkauth_errorsand latency, then roll per application. - Add TLS: deploy certificates, enable
-Zon a new port or instance, migrate clients, then require client certificates where your PKI supports it. - Reduce commands: add
-Fand-Xonce you confirm no tooling depends on them. - Roll back: each change is a startup flag, so keep the previous unit file or configuration in version control and revert by restarting. Plan for the cache being emptied on restart and warm it gradually.
Small and large estates
Small estates: when memcached runs on the same host as a single application, the simplest strong design is a Unix socket (-s) with a tight access mask (-a), or a loopback listener, plus -U 0. Network authentication and TLS add little when no traffic leaves the host, so spend the effort on host hardening and patching instead.
Large estates: when many application hosts share cache clusters, treat memcached like any other internal service. Put clusters in dedicated subnets, issue per-application credentials from your secrets platform, enable TLS with client certificates from your internal CA, and manage startup flags through configuration management so every node carries the same baseline. Feed stats settings into your configuration compliance tooling so drift on any node is flagged within a day, and include cache clusters in regular external exposure scans alongside databases.
Framework mapping
| Control area | NIST SP 800-53 Rev 5 | NIST CSF 2.0 | CIS Controls v8.1 | ISO/IEC 27001:2022 |
|---|---|---|---|---|
| Binding, firewall, UDP off | SC-7, CM-7, SC-5 | PR.PS-01 | 4 (Secure Configuration), 12 (Network Infrastructure) | A.8.20 Networks security |
| SASL, token auth, client certificates | IA-2, IA-5 | PR.AA-05 | 5 (Account Management), 6 (Access Control Management) | A.5.17 Authentication information |
| Disabled admin commands, instance separation | AC-6, CM-7 | PR.AA-05 | 4, 6 | A.8.2 Privileged access rights |
| TLS | SC-8 | PR.DS-02 | 3 (Data Protection) | A.8.24 Use of cryptography |
| Counters and monitoring | AU-2 | DE.CM-01 | 8 (Audit Log Management) | A.8.16 Monitoring activities |
Common misconfigurations
- Relying on the compiled default listener: a source build or minimal container started without
-llistens on all interfaces. Always pass-land check withssornetstatthat only the intended addresses are bound. - UDP enabled by a legacy template: configuration copied from older hosts may carry
-U 11211. Pin-U 0and alert whenstats settingsshows a non-zeroudpport. - Open cloud security groups: a rule allowing 11211 from anywhere, added for testing, stays in place. Scope rules to application subnets and review them automatically.
- One shared cache across trust boundaries: a cache shared by public and internal services lets either read the other's data. Use separate instances and credentials.
- Credentials in plain configuration: SASL passwords or
-Yfiles readable by other users or committed to repositories. Restrict file permissions and load secrets at deploy time. - TLS without client verification: enabling
-Zbut leavingssl_verify_mode=0encrypts traffic yet accepts any client. Combine TLS with SASL,-Yor required client certificates.
Practitioner checklist
- Pass
-lwith loopback or a private address on every instance, or use a Unix socket. - Pin
-U 0and confirmudpportis 0 instats settings. - Restrict 11211 at the firewall and in cloud security groups to application hosts only.
- Enable SASL (
-S) or text protocol auth (-Y) with one credential per application. - Enable TLS (
-Z) for cross-host traffic withssl_min_versionat TLS 1.2 or higher. - Leave
-Aunset and add-Fand-Xwhere the application allows. - Separate instances by application and data sensitivity, with short expiry for cached tokens.
- Collect
statsand alert onauth_errors, connection spikes and settings drift. - Run a supported release and apply vendor security updates promptly.
Standards and references
- Memcached: UDP DDoS advisory
- Memcached: TLS Support
- Memcached: SASL How To
- Memcached: Configuring Server
- Memcached: Protocol documentation (protocol.txt)
- Memcached: 1.5.6 Release Notes
- NIST: SP 800-53 Rev. 5, Security and Privacy Controls
Related NHI Mgmt Group resources: Database Security Guide · Database Credential and Access Security Guide · Secrets Management Guide · DDoS Protection Guide