PortGate

Blueprints · Docker & Databases

Beginner 10 min · Memcached

Memcached localhost bind

Binds Memcached to 127.0.0.1 and turns UDP off. The cache protocol does not authenticate.

Why this should not be public

The memcached text protocol has no authentication: anyone who reaches it reads and changes cached sessions. Its UDP port was abused for record-breaking DDoS amplification in 2018, which is why UDP is off here.

Live config

Baked-in protections

Step 1 · ini

systemd drop-in

/etc/systemd/system/memcached.service.d/bind.conf

Use this when Memcached is already installed from the distro.

[Service]
ExecStart=
ExecStart=/usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -U 0

Step 2 · bash

Reload if the unit exists

/root/portgate-blueprints/memcached-apply.sh

Does nothing destructive when Memcached is not installed.

#!/bin/sh
set -eu
if systemctl list-unit-files | grep -q '^memcached.service'; then
  systemctl daemon-reload
  systemctl restart memcached || echo "Memcached did not restart. Check the binary path in the drop-in."
else
  echo "Memcached is not installed. The drop-in is staged for later."
fi