关于redis:redis配置文件中的保护模式protectedmode

6次阅读

共计 1610 个字符,预计需要花费 5 分钟才能阅读完成。

1. 保护模式

在 redis.conf 配置文件中有这样一个配置:

protected-mode yes

下面有一段正文很好的阐明了它的作用

Protected mode is a layer of security protection, in order to avoid that Redis instances left open on the internet are accessed and exploited.

When protected mode is on and the default user has no password, the server only accepts local connections from the IPv4 address (127.0.0.1), IPv6 address (::1) or Unix domain sockets.

By default protected mode is enabled. You should disable it only if you are sure you want clients from other hosts to connect to Redis even if no authentication is configured.

翻译下:

  1. 保护模式是一个防止你在互联网 (外网) 拜访 redis 的机制。
  2. 当启用保护模式,而且没有明码时,服务器只承受来自 IPv4 地址 (127.0.0.1)、IPv6 地址(::1) 或 Unix 套接字本地连接。(没明码 + 保护模式启动 = 本地拜访)
  3. 默认是开启的。(如果你要从内部拜访它,甚至没有认证 (不设置明码,不绑定可拜访 ip) 的去拜访,那就弄成 no 本人负责!)

2. 相干指令之 bind 指令

bind 127.0.0.1 -::1
这个指明,只能在本地 (运行的节点) 拜访 redis
如果改为其余的,比方 bind * -::* 或者 bind *0.0.0.0 这都全网可拜访了~~~

如果 bind 是内部可拜访的设置,那么保护模式管个球用?!

3. 相干指令之 requirepass 指令

requirepass 123456
这个指明,拜访 redis 时,比方用 redis-cli 拜访,要加个 -a 123456 来认证一下。

如果 requirepass 设置了明码拜访,那么保护模式也不起作用了,它会认为你有密码保护了!

4. 保护模式是否见效的条件

4.1 保护模式起作用

protected-mode yes #关上保护模式
# bind 127.0.0.1 -::1 
# requirepass password // 不设置明码 

下面是起作用的:
bind 127.0.0.1 -::1 #阐明是只能本地拜访
# bind 127.0.0.1 -::1 #用井号正文掉,相当于全网可拜访;然而保护模式开启,能够保障本地拜访。
requirepass password // 设置明码 password, 能够间接通过 -a password 拜访
# requirepass password // 用井号正文掉,相当于无明码拜访;然而保护模式开启,能够保障本地拜访。

4.2 保护模式不起作用

    1. 不起作用 1

      protected-mode yes #关上保护模式
      bind * -::* # 全网可拜访(或者设置了别的 ip)
      # requirepass password #明码拜访
    1. 不起作用 2

      protected-mode yes #关上保护模式
      #bind * -::* # 全网可拜访
      requirepass password #明码拜访
    1. 不起作用 3

      protected-mode yes #关上保护模式
      bind * -::* # 全网可拜访
      requirepass password #明码拜访

5. 总结

1. 如果 protected-mode yes+ 没有 bind x.x.x.x + 没有 requirepass xxxx 设置明码,是起作用的,只能在运行的机器拜访;

  1. 如果 protected-mode yes了 + (设置了 bind x.x.x.x 或者 设置了 requirepass xxxx明码): 前面两者只有有一个开启了,就阐明,你要靠你本人的 bind 或明码来拜访了,它就不起作用了。
正文完
 0