Access memcache on remote serverszalam
By default memcache server is restricted to localhost and cannot be accessed outside server. You have to make configuration changes to allow others to listen memcache server. Now make changes in memcache configuration.
Keep in mind that the -l parameter is set to 0.0.0.0, which essentially allows connections from ANY source. If you keep the standard 127.0.0.1 this will not work.
Next, we make entries to the iptables. If your memcached server is on your LAN, the following command will allow connections only from specific local servers.
For instance, in order to add 111.222.333.444 to the allowed list, we issue the command:
iptables -A INPUT -p tcp -s 111.222.333.444 --dport 11211 -j ACCEPT
If you want to whitelist a remote server, for example, 555.666.777.888 then you issue another command:
iptables -A INPUT -p tcp -s 555.666.777.888 --dport 11211 -j ACCEPT
You can whitelist as many IPs as you want, but be sure to issue the final command that blocks all other connections on that port.
iptables -A INPUT -p tcp --dport 11211 -j REJECT
The IPtables are read in the order they are entered, so if you issue a REJECT ALL statement before issuing any ACCEPT rules, all connections will be rejected (even the whitelisted ones).
You can view firewall rules in IPTables by this command
sudo iptables -L
You can edit rules by this command
You can save IP Tables with this command
To clear all the currently configured rules, you can issue the flush command.
Now memcache would be accessible on remote server. You can check it by issuing the command below.
echo "stats settings" | nc 111.222.333.444 11211
You can also check by telnet
telnet 111.222.333.444 11211