Open Redis port for remote connections

redis connect to remote cluster
redis-cli
redis bigkeys
redis connection refused
redis protected mode
redis commands
redis bind
connect to remote redis server python

I can ping pong Redis on the server:

# redis-cli ping
PONG

But remotely, I got problems:

$ src/redis-cli -h REMOTE.IP ping
Could not connect to Redis at REMOTE.IP:6379: Connection refused

In config, I got the standard port:

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

So maybe I should open port 6379 on the remote Ubuntu machine? How do I do it?

Did you set the bind option to allow remote access on the redis server?

Before (file /etc/redis/redis.conf)

bind 127.0.0.1

After

bind 0.0.0.0

and run sudo service redis-server restart to restart the server. If that's not the problem, you might want to check any firewalls that might block the access.

Important: If you don't use a firewall (iptables, ufw..) to control who connects to the port in use, ANYONE can connect to this Redis instance. Without using Redis' AUTH that means anyone can access/change/delete your data. Be safe!

Redis Remote Connection Configuration, By default redis server listen on the tcp port 6379. This port is ephemeral port (​non privileged) and should be open for external communication for  Configure Redis for remote access. Configure a Google Cloud firewall to open a port. (optional) Connect to Redis from a remote computer. (optional) Before you begin. You'll need a Google Cloud

For me, I needed to do the following:

1- Comment out bind 127.0.0.1

2- Change protected-mode to no

3- Protect my server with iptables (https://www.digitalocean.com/community/tutorials/how-to-implement-a-basic-firewall-template-with-iptables-on-ubuntu-14-04)

Enable remote Redis connection, Enable remote Redis connection. Replaced bind 127.0. 0.1 with bind 0.0. 0.0 in the /etc/redis/redis. conf file, the line does not have a leading # nor space, Replaced protected-mode yes with protected-mode no in this same file, Allowed all traffic to port 6379 using ufw allow 6379 and ufw allow 6379/tcp. I have ensured that UFW allows access to the port. redisServer$ sudo ufw allow from 192.168.xxx.xx to any port 6379 The /etc/redis/redis.conf bind code is: bind 127.0.xxx.xx 192.168.xxx.xx 192.168.xxx.xx 104.237.xxx.xx Here is what I'm using to remotely connect to the Redis server: visitingServer$ redis-cli -h 192.168.xxx.xx -p 6379 -a

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.

Open Redis port for remote connections, I can ping pong Redis on the server: # redis-cli ping PONG. But remotely, I got problems: $ src/redis-cli -h REMOTE.IP ping Could not connect to Redis at  By default redis-cliconnects to the server at 127.0.0.1 port 6379. As you can guess, you can easily change this using command line options. To specify a different host name or an IP address, use -h. to set a different port, use -p.

1- Comment out bind 127.0.0.1

2- set requirepass yourpassword

then check if the firewall blocked your port

iptables -L -n

service iptables stop

Connect to Redis from a different machine, You are strongly advised to only allow access to those ports from trusted Follow these instructions to remotely connect safely and reliably. To connect to Redis from a different machine, you must open port for remote access. Open $REDIS_HOME/redis.conf and uncomment requirepass -YOUR-PASSWORD-HERE- and write down your password in the specified lines. Login to redis using redis-cli and verify your password in the database using auth -YOUR-PASSWORD-HERE- command. Disable protected mode by changing its string in $REDIS_HOME/redis.conf to protected-mode no.

  1. Open $REDIS_HOME/redis.conf and uncomment requirepass -YOUR-PASSWORD-HERE- and write down your password in the specified lines.

  2. Login to redis using redis-cli and verify your password in the database using auth -YOUR-PASSWORD-HERE- command.

  3. Disable protected mode by changing its string in $REDIS_HOME/redis.conf to protected-mode no.

  4. Search for all bind ports values and comment all of them. Just add bind 0.0.0.0 to $REDIS_HOME/redis.conf file.

  5. Disable your firewall or open redis port.

  6. Start redis using ./redis-server $REDIS_HOME/redis.conf.

  7. Check the configuration via ./redis-cli -h -YOUR-IP- -a -YOUR-PASSWORD-HERE-.

  8. Check the configuration via ./redis-cli -h -YOUR-IP- ping.

Redis connection refused for remote connection, There are several items to check for a remote connection to work: To check if Redis port is open $ sudo ufw status Status: active To Action From -- ------ ---- . Configure Redis Remote Access By default, the Redis server doesn’t accept remote connections. You can connect to Redis only from 127.0.0.1 (localhost) - the machine where Redis is running. If you are using a single server setup, where the client connecting to the database is also running on the same host, you should not enable remote access.

How to Install and Configure Redis on Ubuntu 18.04, To configure Redis to accept remote connections open the Redis configuration file with your text editor: Redis is often used as a cache/database that is only available to internal processes on localhost, but sometimes there is a need to allow connections from the outside. Redis listens on TCP port 6379. To allow external Redis access, we can accomplish the goal in one of two ways: Option 1 - Add Redis port directly

Open Redis to accept external connections · GitHub, Open Redis to accept external connections. # Manually secure port 6379. sudo iptables -A INPUT -p tcp --dport 6379 -s xxx.xxx.xxx.xxx -j ACCEPT. sudo iptables​  Lastly, we need to configure the firewall to allow remote connections to the Redis server. To do this, we need to open the redis port which is 6379. So, run the commands below. $ sudo firewall-cmd --add-port=6379/tcp --permanent $ sudo firewall-cmd --reload

redis-cli, the Redis command line interface – Redis, Otherwise it will auto-enable the raw output mode, like in the following example: $ redis-cli incr By default, redis-cli uses a plain TCP connection to connect to Redis. You may Transferring RDB backups from a remote Redis server locally.

Comments
  • redis is not listening on the remote machine?
  • maybe, how to check it
  • Have you disabled ufw?
  • in config file I added string bind 0.0.0.0 after string bind 127.0.0.1. Restarted redis. And now can connect remotly.
  • Is there any difference if we use bind 0.0.0.0 alone vs bind 127.0.0.1 0.0.0.0
  • @Nyxynyx 0.0.0.0 binds to all adapters, so it's unnecessary. Shouldn't make a difference, though.
  • Is it secure to open redis to any ip calls? How can we restricted accessing redis from only certain IPs?
  • @MildlySerious thanks a lot. We have wasted almost 2 weeks figuring out whether firewall or network or some other issue. But this change worked like champ.
  • I had to use bind 0.0.0.0. "bind 127.0.0.1" didn't work for me. I didn't need to set "protected-mode" to "no". Warning: Don't leave empty space before the "bind" or the server won't start. Note: I'm using the windows port of Redis
  • Please don't ever give the advice "Disable your firewall".