|
|
最近在乌云上看到使用memcache没有做ip限制的危害,大家有兴趣的话可以去看看memcached未作IP限制导致缓存数据可被攻击者控制这篇报导,下面我们来看看怎么给memcache做ip限制.
系统:centos 5.9
需要使用到的软件:iptables
memcache限制ip访问的方法:
| 1 | iptables -A INPUT -p tcp -s 192.168.10.5 --dport 11211 -j ACCEPT |
| 2 | iptables -A INPUT -p tcp -s 192.168.10.24 --dport 11211 -j ACCEPT |
| 3 | 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的话,那可以使用下面的这个脚本.
| 2 | ip=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "` |
| 3 | iptables -A INPUT -p tcp -s $ip --dport 11211 -j ACCEPT |
| 4 | iptables -A INPUT -p tcp -m tcp --dport 11211 -j DROP |
| 6 | service iptables restart |
好了,就这样吧.
本文摘自:http://blog.slogra.com/post-428.html
|
|