系统:centos 5.9
需要使用到的软件:iptables
memcache限制ip访问的方法:
代码如下 |
复制代码 |
iptables -A INPUT -p tcp -s 192.168.10.5 --dport 11211 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.10.24 --dport 11211 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 11211 -j DROP
|
然后service iptables save保存规则,最后让iptables重启就可以了.
这里说明下192.168.10.5是你服务端的ip,而192.168.10.24是你客户端的ip.如果你只要服务端访问memcache的话,那可以使用下面的这个脚本.
代码如下 |
复制代码 |
#!/bin/bash
ip=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`
iptables -A INPUT -p tcp -s $ip --dport 11211 -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 11211 -j DROP
service iptables save
service iptables restart
|