Port 11211 (Memcached)

Port 11211 is the default port of Memcached, a caching system that keeps data in memory to reduce the load on the database and speed up websites and…

Key facts

Port
11211
Protocols
TCP, UDP
Range
Registered port, 1024-49151
IANA service name
memcache

IANA assigns ports in this range to services on request, under RFC 6335.

About port 11211

Port 11211 is the default port of Memcached, a caching system that keeps data in memory to reduce the load on the database and speed up websites and applications. The service listens on TCP, and older versions also listened on UDP on the same port by default.

IANA registers port 11211 for the memcache service, on both TCP and UDP.

What port 11211 is used for

  • Cache for websites and applications: query results and frequently repeated data are stored in memory, so the site serves them faster.
  • Sessions: applications can store user session data in Memcached.
  • Shared cache for several servers: several application servers use the same cache, and the client library spreads the data across several Memcached servers.

Port 11211 in the firewall

Memcached isn't built to protect itself from internet connections, so never expose port 11211 to the internet, neither on TCP nor on UDP. When the application and Memcached are on the same server, set it to listen only on 127.0.0.1 (the -l option) and keep the port closed.

When other application servers need access, set it to listen on a private network address, and allow only their addresses in the firewall:

  • UFW: ufw allow from 10.0.0.4 to any port 11211 proto tcp
  • firewalld: firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.4" port port="11211" protocol="tcp" accept'

Risks and security

A Memcached server exposed to the internet on UDP can be abused for DDoS amplification attacks: small requests with a spoofed source address are sent to it, and it sends much larger responses to the spoofed address. That's why UDP is off by default in current versions, and we recommend making sure it's off on older servers too.

  • Turn off UDP with the -U 0 option when you don't use it.
  • Limit listening to 127.0.0.1 or to a private network address.
  • Block port 11211 in the firewall for every address that isn't an authorized application server.
  • SASL authentication adds a layer of protection, but it doesn't replace limiting network access.

Commands to check and configure

  • ss -tulpn | grep ':11211 '

    Shows whether Memcached is listening on port 11211 on TCP and UDP, and on which address. A line with udp means UDP is on.

  • printf 'stats settings\r\nquit\r\n' | nc 127.0.0.1 11211 | grep -E 'tcpport|udpport'

    Shows the ports the service is set to. The value udpport 0 means UDP is off.

  • printf 'stats\r\nquit\r\n' | nc 127.0.0.1 11211

    Shows usage statistics, such as the amount of memory in use and the number of requests found in the cache (hits).

  • nc -zv cache.example.com 11211

    Checks whether port 11211 on the server is reachable from your computer. On a properly configured server, the check from an unauthorized address should fail.

  • systemctl restart memcached

    Restarts the service after a settings change, for example after limiting listening to 127.0.0.1 and turning off UDP.

  • ufw allow from 10.0.0.4 to any port 11211 proto tcp

    Allows access to port 11211 only from the given application server (UFW).

  • firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.4" port port="11211" protocol="tcp" accept'

    Allows access to port 11211 in firewalld only from the given application server. Then run firewall-cmd --reload.

Port 11211 in the IANA registry

Port Protocol Service IANA registry description
11211 TCP memcache Memory cache service
11211 UDP memcache Memory cache service

Data source: IANA Service Name and Transport Protocol Port Number Registry (opens in a new tab)

Port 11211 FAQ

How does Memcached make a site faster?

Memcached keeps data the site needs again and again in memory, such as the results of database queries. When the data is already in the cache, the site gets it from memory instead of querying the database, so pages load faster and the load on the server drops.

What's the difference between Memcached and Redis?

Both keep data in memory and are used as a cache. Memcached is simple and focused on key-value caching. Redis supports more data structures, such as lists and sets, and can also save data to disk, so it's also used for queues and other purposes.

Do I need to open port 11211 for my site to use Memcached?

No, not when the site and Memcached are on the same server. In that case, the site connects to 127.0.0.1, and the port stays closed in the firewall. Open the port only to other application servers, and only to their IP addresses.

How do I check that UDP is off in Memcached?

Run ss -ulpn and check that there's no line with port 11211, or show the settings with the stats settings command and check that the udpport value is 0. When it isn't 0, add the -U 0 option to the service settings and restart it.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement