You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Win11子系统Ubuntu22.04中Redis远程连接被拒绝问题求助

WSL2 Ubuntu中Redis远程连接被拒的解决方案

1. 修改Redis核心配置

  • 打开Redis配置文件:sudo nano /etc/redis/redis.conf
  • 找到bind 127.0.0.1 ::1,注释掉(行首加#),或者改为bind 0.0.0.0,允许所有IP访问Redis服务
  • 找到protected-mode yes,修改为protected-mode no(生产环境建议配合密码认证,这里先解决连接问题)
  • 保存并退出:按Ctrl+O确认保存,Ctrl+X退出编辑器

2. 重启Redis服务生效配置

  • 执行重启命令:sudo systemctl restart redis-server
  • 验证服务状态:sudo systemctl status redis-server,确保显示active (running)

3. 配置WSL2端口映射到Windows主机

  • 在Ubuntu子系统中获取WSL2的IP:ip addr show eth0,找到inet字段后的IP地址(比如172.18.0.2)
  • 打开Windows管理员权限的命令提示符,添加端口转发规则:
    netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=6379 connectaddress=你的WSL_IP connectport=6379
    
  • 验证转发规则:netsh interface portproxy show all,确认6379端口的转发条目存在

4. 放行防火墙端口

  • Ubuntu子系统中开放6379端口:sudo ufw allow 6379/tcp,或者临时关闭防火墙测试:sudo ufw disable
  • Windows系统中添加入站规则:打开Windows Defender防火墙→高级设置→入站规则→新建规则,选择端口,允许TCP 6379端口的连接

5. 测试远程连接

  • 远程机器执行命令:redis-cli -h Windows主机的公网/局域网IP -p 6379,注意这里用的是Windows主机的IP,不是WSL2的内部IP

内容的提问来源于stack exchange,提问作者ikillapps

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 08:02:36