Open Redis port for remote connections

后端 未结 10 1998
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 10:00

I can ping pong Redis on the server:

# redis-cli ping
PONG

But remotely, I got problems:

$ src/redis-cli -h REMOTE.IP ping
         


        
相关标签:
10条回答
  • 2020-12-07 10:40

    Another possibly helpful note.

    Redis can be bound to multiple IPs - that's very helpful when you don't want to open it to entire world (0.0.0.0) but only make it accessible in local networks.

    1. sudo nano /etc/redis/redis.conf
    2. add your local network IP to the end of bind setting:

    bind 127.0.0.1 10.0.0.1

    1. restart the service: sudo service redis-server restart

    Now you can easily access redis from other computers in same network, e.g. redis-cli -h 10.0.0.1

    0 讨论(0)
  • 2020-12-07 10:41

    A quick note that doing this without further securing your Redis server is not a good idea as it can leave you open to attack. Be sure to also implement AUTH or otherwise secure that. See http://redis.io/topics/security for details.

    0 讨论(0)
  • 2020-12-07 10:48

    A quick note that if you are using AWS ec2 instance then there is one more extra step that I believe is also mandatory. I missed the step-3 and it took me whole day to figure out to add an inbound rule to security group

    Step 1(as previous): in your redis.conf change bind 127.0.0.1 to bind 0.0.0.0

    Step2(as previous): in your redis.conf change protected-mode yes to protected-mode no

    important for Amazon Ec2 Instance:

    Step3: In your current ec2 machine go to the security group. add an inbound rule for custom TCP with 6379 port and select option "use from anywhere".

    0 讨论(0)
  • 2020-12-07 10:49
    1. Open the file at location /etc/redis.conf

    2. Comment out bind 127.0.0.1

    3. Restart Redis:

       sudo systemctl start redis.service
      
    4. Disable Firewalld:

       systemctl disable firewalld
      
    5. Stop Firewalld:

       systemctl stop firewalld
      

    Then try:

    redis-cli -h 192.168.0.2(ip) -a redis(username)
    
    0 讨论(0)
  • 2020-12-07 10:51

    Bind & protected-mode both are the essential steps. But if ufw is enabled then you will have to make redis port allow in ufw.

    1. Check ufw status ufw status if Status: active then allow redis-port ufw allow 6379
    2. vi /etc/redis/redis.conf
    3. Change the bind 127.0.0.1 to bind 0.0.0.0
    4. change the protected-mode yes to protected-mode no
    0 讨论(0)
  • 2020-12-07 10:53

    In my case, I'm using redis-stable

    Go to redis-stable path 
     cd /home/ubuntu/software/redis-stable
    

    Open the redis.conf

    vim redis.conf
    

    Change the bind 127.0.0.1 to bind 0.0.0.0

    change the protected-mode yes to protected-mode no

    Restart the redis-server:

    /etc/init.d/redis-server stop
     redis-server redis.conf
    
    0 讨论(0)
提交回复
热议问题