Describe the bug
The redis.conf file already contains bind 127.0.0.1 ::1. This seems to work. But if redis is started with --port 7777 for example, then I'm seeing it bind to all interfaces on port 7777, not just loopback on port 7777.
To reproduce
From the CLI, run: /usr/bin/redis-server --port 7777.
Then run netstat -lntp to see all the opened ports:
> sudo netstat -lntp | egrep -i "redis|Local"
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 1582/redis-server 1
tcp 0 0 0.0.0.0:7777 0.0.0.0:* LISTEN 25902/redis-server
tcp 0 0 0.0.0.0:7778 0.0.0.0:* LISTEN 25906/redis-server
tcp6 0 0 ::1:6379 :::* LISTEN 1582/redis-server 1
tcp6 0 0 :::7777 :::* LISTEN 25902/redis-server
tcp6 0 0 :::7778 :::* LISTEN 25906/redis-server
Expected behavior
Shouldn't it bind only localhost, not 0.0.0.0?
If not, is there a different parameter to get it to bind to a local address? I also tried: /usr/bin/redis-server --port 127.0.0.1:7777
...but unsurprisingly this did not work. Instead, that results in Redis binding to 0.0.0.0:127 instead.
Additional information
> dpkg -l | grep redis
ii libhiredis-dev:amd64 0.13.3-2.2 amd64 minimalistic C client library for Redis (development files)
ii libhiredis0.13:amd64 0.13.3-2.2 amd64 minimalistic C client library for Redis
ii redis 5:4.0.9-1ubuntu0.2 all Persistent key-value database with network interface (metapackage)
ii redis-server 5:4.0.9-1ubuntu0.2 amd64 Persistent key-value database with network interface
ii redis-tools 5:4.0.9-1ubuntu0.2 amd64 Persistent key-value database with network interface (client)
Comment From: oranagra
@stephanecharette i'm not entirely sure what you're missing or if indeed there's a problem.
first there's the --bind argument that corresponds to the bind line in the config file.
so like you used --port you can use --bind.
secondly you should be aware (in case you're not), that redis doesn't include the redis.conf by default, if you want it you need to use redis-server redis.conf, and you can add extra config arguments to add or override configs, e.g. redis-server redis.conf --port 7777.
also, be aware that the defaults with which redis starts are not necessarily the defaults that are in the bundled redis.conf file. specifically, the default bind is currently defined here:
#define CONFIG_DEFAULT_BINDADDR { "*", "-::*" }
in the past, it was defined differently, but with similar outcome:
/* Force binding of 0.0.0.0 if no bind address is specified, always
* entering the loop if j == 0. */
lastly, you should be aware that there where quite a few changes in that area recently, so maybe the bug you're seeing is already solved.
look for bind in https://github.com/redis/redis/blob/6.2/00-RELEASENOTES
and also have a look at this (only in the unstable now for now): https://github.com/redis/redis/pull/9034
Comment From: stephanecharette
Thank you. The --help output does not mention the --bind parameter. That does give us what we need. I was also not aware that the redis.conf file is not included by default. That is good to know, I'll let the team know.
Comment From: oranagra
i see the help is just a bunch of examples. basically any parameter in the config file can also be provided by command line arguments.