I installed redis on my server. I am unable to connect to server with ip address but able to connect with localhost
. I am unable to connect to this redis from other servers too. What could be the reason?
ubuntu@ip-172-31-91-211:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
inet 172.31.70.211 netmask 255.255.240.0 broadcast 172.31.95.255
inet6 fe80::1052:1ff:fee4:cfdd prefixlen 64 scopeid 0x20<link>
ether 12:52:01:e4:cf:dd txqueuelen 1000 (Ethernet)
RX packets 974 bytes 304521 (304.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 937 bytes 130927 (130.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 794 bytes 63335 (63.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 794 bytes 63335 (63.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ubuntu@ip-172-31-91-211:~$ redis-cli -h 172.31.70.211
Could not connect to Redis at 172.31.70.211:6379: Connection refused
not connected>
ubuntu@ip-172-31-91-211:~$ redis-cli -h localhost
localhost:6379>
ubuntu@ip-172-31-91-211:~$ redis-cli -h 127.0.0.1
127.0.0.1:6379>
ubuntu@ip-172-31-91-211:~$
I am able to connect to this process with ip address when it is different application
ubuntu@ip-172-31-70-211:~$ python3 -m http.server 6379 &
[1] 992
ubuntu@ip-172-31-70-211:~$ Serving HTTP on 0.0.0.0 port 6379 (http://0.0.0.0:6379/) ...
ubuntu@ip-172-31-70-211:~$ curl 172.31.91.211:6379
172.31.91.211 - - [27/Mar/2023 07:01:42] "GET / HTTP/1.1" 200 -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /</title>
</head>
<body>
<h1>Directory listing for /</h1>
<hr>
<ul>
<li><a href=".bash_history">.bash_history</a></li>
<li><a href=".bash_logout">.bash_logout</a></li>
<li><a href=".bashrc">.bashrc</a></li>
<li><a href=".cache/">.cache/</a></li>
<li><a href=".profile">.profile</a></li>
<li><a href=".rediscli_history">.rediscli_history</a></li>
<li><a href=".ssh/">.ssh/</a></li>
<li><a href=".sudo_as_admin_successful">.sudo_as_admin_successful</a></li>
<li><a href=".viminfo">.viminfo</a></li>
<li><a href="Development/">Development/</a></li>
</ul>
<hr>
</body>
</html>
Try to change bind IP
Go to the redis file location and open the Redis configuration file with a text editor
sudo nano /etc/redis/redis.conf
change bind IP (you can use allowed need IP also)
bind 0.0.0.0 ::
finally restart the redis
sudo systemctl restart redis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With