【问题标题】:Allow Redis connections from only localhost?只允许来自本地主机的 Redis 连接?
【发布时间】:2017-02-28 02:54:24
【问题描述】:

我在我的网络服务器 (Debian/Nginx/Gunicorn) 上运行 Redis 以进行会话存储,并且有理由相信我的 Redis 服务器被黑客入侵了。这绝对是可能的,因为如果我在另一台机器上针对 Web 服务器运行命令“redis-cli -h (HOST IP)”,我可以进入控制台并运行命令。我有两个问题。首先,如果我向我的 iptables 文件添加一个新部分,如下所示,我是否会正确阻止除网络服务器本身之外的所有机器对我的 Redis 服务器的访问? Redis 在默认端口 6379 上运行。

*filter

-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -s 127.0.0.0/8 -j REJECT

# Allow pings, SSH, and web access
-A INPUT -p icmp -m state --state NEW --icmp-type 8 -j ACCEPT
-A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
-A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
-A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT

# NEW SECTION...
# IS THIS CORRECT?
-A INPUT -p tcp --dport 6379 -j DROP
-A INPUT -p tcp -s 127.0.0.1 --dport 6379 -m state --state NEW -j ACCEPT
# END NEW SECTION

-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -j REJECT
-A FORWARD -j REJECT

COMMIT

其次,如果以上都正确的话,我的iptables的IPv6版本还可以使用127.0.0.1还是需要使用“::1”?

谢谢。

【问题讨论】:

    标签: redis firewall iptables


    【解决方案1】:

    您应该可以通过Redis configuration file

    # By default Redis listens for connections from all the network interfaces  
    # available on the server. It is possible to listen to just one or multiple 
    # interfaces using the "bind" configuration directive, followed by one or 
    # more IP addresses. 
    # 
    # Examples: 
    # 
    # bind 192.168.1.100 10.0.0.1 
    # bind 127.0.0.1
    

    【讨论】:

    • 我一直在解决另一个问题,但一旦我解决了它,我就会实施你的答案,测试它是否有效,并给予你信任。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2016-07-16
    • 2018-08-28
    • 2016-03-21
    • 2019-11-03
    • 1970-01-01
    • 2019-01-03
    相关资源
    最近更新 更多