If you want to access redis database from remote client or even server then you would need to configure redis to accept remote connection by binding server IP Address.
Redis Configuration - Remote Connections
As good security practice redis by default does not allow remote client to connect to the server. This configuration can be overridden with following steps.
- Get Public IP Address of Redis Server
You can use command like
ifconfig
on linux andipconfig
on windows to find IP address of your server. Below you can see public ip address of the redis server tagged underinet
address which is93.184.216.34
ifconfig bash-4.2$ ifconfig .... inet 93.184.216.34 .....
- Get Port 6379 Opened If blocked.
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 non root (non admin) users. But incase your network admin has blocked this port then you would need to get it opened by changing firewall rules. Consult with your system or network admin to change firewall rule.
- Change redis configuration to bind IP address.
- Move to the redis server installation directory.
cd /home/techmonger/redis/redis-4.0.11/
- Open redis configuration file
redis.conf
(Linux) orredis.windows.conf
(Windows) - Uncomment following line and bind IP address of your redis server.
Default Configuration
Configuration after Enabling Remote Access with Bind# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #bind 127.0.0.1
bind 127.0.0.1 93.184.216.34
- Start the redis instance with configuration file.
- Start Redis Server - Linux
cd /home/techmonger/redis/redis-4.0.11/src/ ./redis-server ../redis.conf
- Start Redis Server - Windows
cd C:\Users\techmonger\Documents\Programs redis-server.exe redis.windows.conf
- Start Redis Server - Linux
- Move to the redis server installation directory.
- Secure Remote Access with Password
With above configuration any client on the internet will be able to connect to the redis server. It is important to have an authentication mechanism enabled by setting strong password and then connect to the redis database remotely.
Note that your machine running redis server must have public ip address, if it is running behind NAT then it will not be to listen for remote connections.
Conclusion
We have learned how to bind server IP address and expose redis database which can be accessed from outside local machine on which it is running.