0

I am trying to figure out how I can connect to a Redis client which should be blocking all Redis connections over TCP on port 6379. The ruby client I'm using, and telnet, can both connect and execute commands. The golang client I'm using can't, and I'm really confused as to why.

Here's my iptables definition:

root@server:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  localhost            anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
DROP       all  --  anywhere             anywhere
DROP       tcp  --  anywhere             anywhere             tcp dpt:6379

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
DOCKER     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (1 references) target prot opt source destination

Heres sample output indicating that I can't connect/telnet from my other port host using Golang:

FATAL: 2015/08/06 21:05:13 redis.go:43: Failed to register hostname with Redis.
FATAL: 2015/08/06 21:05:13 redis.go:44: dial tcp 95.105.137.209:6379: i/o timeout

Heres sample output indicating that I can connect from redis-rb:

irb(main):003:0> host = "myserver.io"
=> "myserver.io"
irb(main):004:0> port = 6379
=> 6379
irb(main):005:0> require 'redis'
=> true
irb(main):006:0> r = Redis.new(host: host, port: port, password: pass)
=> #<Redis client v3.2.1 for redis://myserver.io:6379/0>
irb(main):007:0> r.get('wat')
=> "yaaaa32"

Both client examples are from the same host. Can anyone point me in the right direction?

Thomas V.
  • 601
  • 4
  • 12
  • 1
    Connect using the *exact* same IP address in both. I bet myserver.io is resolving to 127.0.0.1, which is why it passes though iptables. – JimB Aug 06 '15 at 21:20
  • Thanks for the advice @JimB. I tried connecting to redis via IP address (which my go client was resolving to for the myserver.io address), and I got the expected consequences. That makes me curious though as to how myserver.io is resolving to 127.0.0.1. Is my loopback misconfigured? – Thomas V. Aug 06 '15 at 23:40

1 Answers1

0

The problem was redis-rb was defaulting to connect via IPv6, whereas go-dockerclient was connecting via IPv4. In hindsight it was completely obvious, though I assumed the error had to do with inexperience relating to iptables.

Thomas V.
  • 601
  • 4
  • 12