Loopback host address ('localhost','127.0.0.1', etc.) resolves to network IP
See original GitHub issueExpected behavior
I have my Jedis client configured to connect to localhost
.
I expect the connection to be made to the localhost via loopback.
Actual behavior
As of the changes in https://github.com/xetorthio/jedis/pull/1342, when specifying a localhost
address, it now resolves to my machine’s network ip address.
This makes it impossible to connect to a redis-sentinel
on localhost because the sentinel only allows connections from loopback on more recent versions of Redis.
Steps to reproduce:
- Initialize a Jedis 2.9.+ client with the host
'localhost'
- Unable to connect to local redis-sentinel (version 3.2.2) because
'localhost'
resolved to an external ip (i.e.10.1.10.254
).
I think the new behavior in getLocalHostQuietly()
introduces system-dependent behavior via InetAddress.getLocalHost().getHostAddress()
, which does not seem to be the intent of the code.
Redis / Jedis Configuration
Jedis version:
2.9.x (since https://github.com/xetorthio/jedis/pull/1342)
Redis version:
3.2.2
Java version:
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
What Is the 127.0.0.1 IP Address? - Lifewire
The IP address 127.0.0.1 is a special-purpose IPv4 address and is called the localhost or loopback address. All computers use this address ...
Read more >How does localhost 127.0.0.1 work? - Super User
IP datagrams sent by a host to a 127.x.x.x loopback address are not passed down to the data link layer for transmission. Instead,...
Read more >What is the difference between 127.0.0.1 and localhost
On modern computer systems, localhost as a hostname translates to an IPv4 address in the 127.0.0.0/8 (loopback) net block, usually 127.0.0.1, or ::1...
Read more >Why does my hostname appear with the address 127.0.1.1 ...
It is (debatably) useful to have an entry in your /etc/hosts translating the machine's fully-qualified domain name into its permanent IP address.
Read more >What is localhost? How to connect to 127.0.0.1 - IONOS
127.0.0.1 – how does loopback work? IP addresses are used within a network to communicate with each other. Each participant in the network...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
One of possible workarounds is to set it explicitly
then jedis will not try to resolve it.
From Jedis 3.6.0 (due to #2445), there are two new constructors with
Set<HostAndPort> sentinels
param. These constructors will not convert the hosts and treat the hosts as they are provided.