0

I have just installed Redis on a remote Ubuntu machine (VM configurations) and used port forwarding to be able to access it from a remote client. Redis is working correctly on the machine itself : I am able to get response for 'ping' commands sent through redis-clients on the same machine. However, when I try to access the Redis server from a remote-machine (using a jedis client for a java application), I get a socket time-out error.

On researching the problem a little, I realized that the redis-server on the remote machine is not working as a service. The output of the service command is given below which shows that the redis-server service is currently stopped ([-] option in front of "redis-server").

Also, using netstat command, I have ensured that the port 6379 is assigned to redis-server. Attached below is the snapshot of the same. enter image description here

Also, in my configuration file (redis.conf), I have uncommented the line that binds the server to 127.0.0.1 and also changed the "daemon" option to 'yes'. I start the server using this config file.

Any help on how I can access the remote server (or run the service in the background such that it actively listens for new connections) through my application is highly appreciated! Thanks in advance.

BajajG
  • 2,134
  • 2
  • 25
  • 32
  • Edit: I have also changed the binding from 127.0.0.1 to 0.0.0.0 but it also doesn't work – BajajG Jun 20 '14 at 09:23
  • You should ideally get the following response : netstat -a | grep 6379 tcp 0 0 *:6379 *:* LISTEN – Chhavi Gangwal Jun 22 '14 at 10:16
  • How do you start your server ? You should ideally start it along with path to your config file where you have made the changes . Look for updated answer. – Chhavi Gangwal Jun 22 '14 at 10:18
  • I always start my server with the config file path. I figured out the problem. The port on the remote machine was assigned to redis but was being blocked by the firewall. After opening the port for remote connections, I was able to run it properly. But thanks for you time. I greatly appreciate your help. – BajajG Jun 23 '14 at 07:30

2 Answers2

0

Whether in background or not, Redis does only listen to localhost by default. To make it listen to all IP-Addresses comment out the 'bind'-line completely (prefix with '#').

Just remember: Making Redis publically available (e.g. exposing its port to the Internet) may be a security risk. Redis has no sophisticated integrated security, as you can only set a simple global password. Due to its performance (50000+ gets per second on an anverage machine) this password is very prone to bruteforcing attempts. You can instead use SSH-tunneling to access your redis instance. Just remember to change your bind back to 127.0.0.1 in this case.

Peter Brennan
  • 1,366
  • 12
  • 28
  • I tried commenting the 'bind' line but no luck. Currently I am binding it to 0.0.0.0 for accessing it globally. Still, nothing works. – BajajG Jun 21 '14 at 14:30
  • First of all, I am glad to hear you got your remote connection up and running. You may however still consider my secure connection approach. I have done so myself for several C# applications and it works like a charm. I am using a C# ssh library to connect to the server redis runs on (on port 22), tunneling the redis port from client-localhost to server-localhost. I then connnected my redis-client on the client machine to localhost and voila: secure encrypted connection. There has to be some easy to use java lib for ssh (I just don't know one by name, I'm not very experienced in java)... – Peter Brennan Jun 26 '14 at 09:19
  • Thanks for the suggestion. I will surely try that! :) – BajajG Jun 27 '14 at 06:35
0

All you need to do here is : In your redis.conf file change

bind 127.0.0.1

to

bind 0.0.0.0

and restart your server

sudo src/redis-server

Check this out : Redis - Connect to Remote Server

Community
  • 1
  • 1
Chhavi Gangwal
  • 1,166
  • 9
  • 13