Redis bind to more than one IP

Redis

Redis Problem Overview


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.

Redis Solutions


Solution 1 - Redis

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

Solution 2 - Redis

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.

Solution 3 - Redis

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!!

Solution 4 - Redis

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

Solution 5 - Redis

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.

Solution 6 - Redis

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.

Solution 7 - Redis

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

bind 111.222.33.44
bind 127.0.0.1 ::1

Solution 8 - Redis

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionspacemilkmanView Question on Stackoverflow
Solution 1 - RedismahemoffView Answer on Stackoverflow
Solution 2 - RedisSerob_bView Answer on Stackoverflow
Solution 3 - Redisuser1092559View Answer on Stackoverflow
Solution 4 - RedisPaulo CoghiView Answer on Stackoverflow
Solution 5 - RedisAgent47DarkSoulView Answer on Stackoverflow
Solution 6 - RedisGlenn PlasView Answer on Stackoverflow
Solution 7 - RedisAntónio AlmeidaView Answer on Stackoverflow
Solution 8 - RedisclarkttfuView Answer on Stackoverflow