IPTables和不同Redis客户端的奇怪问题

时间:2015-08-06 21:08:18

标签: ruby ubuntu go iptables

我试图找出如何连接到Redis客户端,该客户端应该阻止端口6379上通过TCP的所有Redis连接。我正在使用的ruby客户端和telnet都可以连接和执行命令。我正在使用的golang客户端不能,我真的很困惑为什么。

这是我的iptables定义:

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个参考文献) 目标prot opt源目的地

下载示例输出,表明我无法使用Golang从我的其他端口主机连接/ telnet:

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

下载样本输出,表明我可以从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"

两个客户端示例都来自同一主机。有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:0)

问题是redis-rb默认通过IPv6连接,而go-dockerclient通过IPv4连接。事后看来,这是完全明显的,虽然我认为错误与iptables相关的经验不足有关。