Implementing Network ACL for Memcached Using iptables
This article explains how to use Linux iptables to create network-level ACLs that block non-production IP ranges from accessing a Memcached server, providing command examples for adding, listing, and clearing firewall rules, and discusses future considerations such as IPv6 support.
Introduction
Solving problems can take many paths; the author prefers using built-in system tools as “Swiss army knives” rather than IDE shortcuts.
Requirement
Memcached lacks built-in ACL, leading developers to accidentally connect development environments to production, causing data pollution. Various solutions exist, but the author advocates a simple network-level rule using iptables to block unwanted access.
Analysis
The simplest ACL is to reject traffic at the network layer; on Linux the iptables command is the natural choice.
iptables Settings
To allow only the production subnet (e.g., 10.6.0.0/16) to reach the Memcached port (11211) and reject everything else, run:
# iptables -A INPUT -p tcp -s 10.6.0.0/16 --dport 11211 -j ACCEPT
# iptables -A INPUT -p tcp --dport 11211 -j REJECTSupplement
In a real environment you may edit the firewall file directly, for example:
*filter
……
-A INPUT -j dujiape_input
-A dujiape_input -i lo -j ACCEPT
-A dujiape_input -s 10.0.0.0/16 -m state --state NEW -j ACCEPT
…………
-A dujiape_input -p tcp --dport 11211 -m state --state NEW -j DROP
-A dujiape_input -j ACCEPT
COMMITClear Rules
To flush all iptables rules: iptables -F If other rules exist, copy them before flushing and restore them afterward.
List Rules
To view current firewall rules:
iptalbes -LPostscript
iptables will likely be used for a few more years, but with IPv6 adoption the future command may be ip (8), which supports both IPv4 and IPv6.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
