I was struggling with the remote connection to Redis for some days. Finally I made it. Here is the full check list I put together to follow to get connected. Some of solutions are given in the answers above. Yet I wanted my answer to be a nano-wiki on the subject:) I added some useful links too.
If redis works locally:
$ redis-cli
127.0.0.1:6379>ping
PONG
127.0.0.1:6379>
If the password is not set
See /etc/redis/redis.conf
config (this is default locaion for Ubuntu 18.04, you may have it in the different location):
# The following line should be commented
# requirepass <some pass if any>
If the protected mode is set to 'no' in the config:
# The following line should be uncommented
protected-mode no
if the IP binding is open for an access from internet in the config:
# The following line should be commented
# bind 127.0.0.1 ::1
If the Linux firewall allows connections
(here for Ubuntu 18.04) Check it allows for incoming internet traffic to go to port 6379
(the Redis default port)
# To check if it the port is open
$ sudo ufw status
Status: active
To Action From
-- ------ ----
...
6379/tcp ALLOW Anywhere
6379/tcp (v6) ALLOW Anywhere (v6)
...
# To open the port
$ sudo ufw allow 6379/tcp
Restart Redis service
Do not forget to restart the Redis service for changes to take effect and see it is running:
$ sudo systemctl restart redis.service
$ sudo systemctl status redis
Check if it works as a remote server
from your command line use redis-cli
as if Redis server were on the remote server:
$ redis-cli -h <your-server-ip>
<your-server-ip>:6379> ping
PONG
<your-server-ip>:6379> exit
$
If you can ping-PONG your Redis server via your internet server connected as a remote server than the remote Redis connection works.
Security Warning
All the above makes your Redis data to be completely open to anybody from the internet.
To basically secure Redis use requirepass
and protected-mode yes
settings in Redis config (see above) and block the dangerous Redis commands (see the link above), for a deeper understanding see this article and Redis site security section ).
Useful links
Some links to help How to install and secure Redis on Ubuntu 18.04 and how to setup Ubuntu 18.04 firewall.
Hope it helps.