Redis bind 限制和指定IP访问

本文介绍了Redis的bind配置,澄清了其作用并非指定客户端IP访问,而是指定了服务器网卡IP。当bind设置错误时,可能造成Redis无法启动。为限制或指定IP访问,建议在内网中通过网络接口限制,公网环境下使用iptables规则。注意,bind不能直接实现指定IP访问Redis的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Redis Version

Redis server v=3.2.3

参考

https://segmentfault.com/q/1010000002921259

http://blog.youkuaiyun.com/hel12he/article/details/46911159

关于bind

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
#默认情况下,如果没有声明bind指令,Redis会监听服务器上所有可用的网络接口(网卡)上的连接。
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#可以用bind指令指定Redis监听的一个或多个网络接口(网卡),示例如下:
#
# Examples:
#
#bind 192.168.10.3 192.160.10.4 127.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet,  binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
#如果你的Redis部署在公网上,并且监听所有网络接口(网卡),那么你的Redis示例便暴露给了互联网上的每个人,这样是很危险的。
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1
  • 意思是说 bind 指定是Redis所在服务器网卡的ip,不是指定某些IP可以访问本机Redis实例
  • 如果你的bind指定的不是本机网卡IP,那么可能导致你的Redis实例无法启动

如何限制或指定IP访问呢?

  1. 如果是内网访问,通过网络接口(网卡)限定,让客户端访问固定网卡连接redis
  2. 如果是公网,通过iptables指定某个IP允许访问!!

总之,通过bind是无法指定某个IP来访问redis的。这在网上是一个很大的误区!!

转载于:https://my.oschina.net/ironwill/blog/902006

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值