54

In the redis.conf the normal setting is

bind 127.0.0.1

I want redis to listen to another ip too (say my local development address)

I tried

bind 127.0.0.1, 123.33.xx.xx

but this does not work. I cannot find any relevant in the document or by googling. Hope someone can help.

Sripathi Krishnan
  • 30,948
  • 4
  • 76
  • 83
spacemilkman
  • 943
  • 1
  • 9
  • 15
  • The normal setting is not to have `bind` set at all, which will make Redis bind to all interfaces. I'm not sure if you can make it listen to two (or more) *specific* addresses (it's not documented that it can, AFAIK). – robertklep Apr 20 '13 at 13:04
  • I am not sure if I get the meaning of bind right, so if one left the bind line commented out, does it means that anybody can connect to your redis server and get the content? – spacemilkman Apr 20 '13 at 14:33
  • 5
    If you require it to listen multiple interfaces, just listen on all possible and use firewall to restrict access to the service. – taro Apr 20 '13 at 14:43
  • @taro thats should be an answer (the right one imho) :) – Tommaso Barbugli Apr 20 '13 at 14:45
  • @user2122139 yes, if you leave it commented out anyone can connect to it (unless they are blocked somehow, by firewall or NAT or something) – robertklep Apr 20 '13 at 14:46

8 Answers8

45

Binding to multiple IPs is indeed possible since Redis 2.8. Just separate each IP by whitespace (not commas).

bind 127.0.0.1 123.33.xx.xx

Source: Official default config

mahemoff
  • 44,526
  • 36
  • 160
  • 222
  • 1
    When I add a second IP address and then `sudo systemctl restart redis-server.service` (Ubuntu) then I get an error that says `redis-server.service: Start request repeated too quickly.` I had to `stop`, then wait for a while before calling `start`. – Jens Feb 04 '18 at 05:54
  • On Ubuntu, find the `bind` and modify in `/etc/redis/redis.conf` – gies0r Aug 09 '19 at 14:19
  • 4
    Unfortunately I get `Job for redis-server.service failed because a timeout was exceeded.` – Ryan Nov 04 '19 at 20:00
23

This answer is not outdated and will work for both older and newer versions

The problem in understanding is that Redis binding doesn't show the client machine's address, but shows the interface through which connection should be established. In your example, if your local development (client) address is 123.33.xx.xx, it doesn't mean that you have to put exactly the same address as a binding, otherwise Redis service will not start.

So if ifconfig on your Redis server machine shows that you have some network interface similar to this:

eth0   Link encap:Ethernet  HWaddr 00:0c:... 
       inet addr:192.168.1.110  Bcast:192.168.1.255  Mask:255.255.255.0

you can put the interface's address 192.168.1.110 as a binding and every request to Redis, which pass through this interface, should succeed.

Serob_b
  • 965
  • 12
  • 29
  • 1
    This worked perfectly for me. Thanks! Is this a safe, production-env approved method? – CodingInCircles Mar 26 '18 at 19:43
  • @CodingInCircles Actually I don't remember if I met this explanation in the official doc or not. I just tried and found it by myself.I think it is the only method to make Redis work :D Maybe for security reasons you can use some firewalls etc. On my Redis server I didn't have any security issues concerning to this method while used it, but who knows... – Serob_b Mar 26 '18 at 20:12
  • This seemed to be the most straightforward and quickest method to get clients to connect to the server and run. I'm trying to get an Airflow cluster up and running and I'm using Redis as the backend. This method worked fine with protected-mode enabled, and so I was encouraged, but not sure if this is totally safe. Thank you for the answer though :) – CodingInCircles Mar 26 '18 at 20:14
  • CodingInCircles Good luck)) – Serob_b Mar 26 '18 at 20:17
14

Since:

--[ Redis 2.8 Release Candidate 1 (2.7.101) ] Release date: 18 Jul 2013

you can:

  • [NEW] Ability to bind multiple IP addresses.

Cheers!!

user1092559
  • 187
  • 1
  • 3
10

Edit: it seems that the correct way is, still, only one line and one or more IPs separated by space

This way:

bind 127.0.0.1 10.150.220.121
Paulo Coghi
  • 13,724
  • 14
  • 68
  • 90
  • 2
    This change is now documented, including an example in the config file: http://download.redis.io/redis-stable/redis.conf – Paulo Coghi Oct 18 '16 at 02:46
4

EDIT: This is an outdated answer. Please check newer answers for solution.

You cannot set redis to listen on specific multiple interfaces. If multiple interfaces are required just remove the bind line.

As @taro pointed out use firewall to restrict access.

Agent47DarkSoul
  • 448
  • 5
  • 13
3

I tried finding that answer too, as it stands, it's not possible to do this, I found this while searching for the answer on multiple (but not all interfaces). This is what turned up http://code.google.com/p/redis/issues/detail?id=497 stating it will not be supported by redis itself.

In conjunction with haproxy that makes it impossible to put it in front of redis in one go. You need to use a different port, or the other or choose to bind on 1 IP.

Glenn Plas
  • 1,608
  • 15
  • 17
3

The only way this worked for me, was by adding separate lines:

bind 111.222.33.44
bind 127.0.0.1 ::1
António Almeida
  • 9,620
  • 8
  • 59
  • 66
1
bind 127.0.0.1 192.168.152.2

Note, I have to put the 127.0.0.1 first otherwise the 192.x will not be bound at system boot. However another systemctl restart redis will suffice -- might be a bug? (Debian 10 and Redis 5.0.3)

For macOS Homebrew installation, make sure you are editing /usr/local/etc/redis.conf instead of the template file: /usr/local/Cellar/redis/6.2.6/.bottle/etc/redis.conf

clarkttfu
  • 577
  • 6
  • 11