  
TA的每日心情 | 擦汗 1 小时前 |
---|
签到天数: 1670 天 [LV.Master]伴坛终老
|
之前在乌云上看到使用memcache没有做ip限制的危害,下面我们来看看怎么给memcache做ip限制.
系统: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
复制代码 |
|