AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1423860
Accepted
Biel
Biel
Asked: 2019-04-11 08:23:33 +0800 CST2019-04-11 08:23:33 +0800 CST 2019-04-11 08:23:33 +0800 CST

Debian 9 服务器上的 Node-RED 无法连接到 MQTT 代理

  • 772

我的 Node-RED 流程:

[{"id":"6c5780e.7e86f","type":"mqtt in","z":"fa8ef0ce.69a348","name":"","topic":"bs/esp8266/ldr","qos":"2","datatype":"auto","broker":"11952de3.32d7b2","x":320,"y":420,"wires":[["e5ac261a.a24058"]]},{"id":"11952de3.32d7b2","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

我有一个连接到本地主机(本地 mosquitto 服务器)的 MQTT 节点和连接到 HiveMQ 代理的 4 个节点。他们都无法连接。

我的 iptables 规则:

Chain INPUT (policy DROP 243 packets, 11542 bytes)
 pkts bytes target     prot opt in     out     source               destination
   34  1700 ACCEPT     all  --  lo     any     anywhere             anywhere
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:1883
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:1883
  735 80016 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:1880
  771 55433 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp dpt:3000

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy DROP 156 packets, 11397 bytes)
 pkts bytes target     prot opt in     out     source               destination
   34  1700 ACCEPT     all  --  any    lo      anywhere             anywhere
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp spt:1883
    0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp spt:1883
 1175 2794K ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp spt:1880
 2369 6542K ACCEPT     tcp  --  any    any     anywhere             anywhere             tcp spt:3000

我可以从另一台机器(安装了 Node-RED 的 Windows 机器)连接到我的 mosquitto 服务器,甚至可以使用 MQTTS 和证书。

我在想也许问题取决于我的 iptables 规则,但我不确定,而且我是这个主题的初学者。先感谢您。

编辑:在修改我的 iptables 规则之前,我可以从我的 Windows 机器连接到代理。对于新的(我最初粘贴在这里的那些)它没有连接。我以前只使用过这些规则,当它仍然有效时:

sudo iptables -A INPUT -p tcp --dport 1883--jump ACCEPT
sudo iptables -A INPUT -p tcp --dport 8883--jump ACCEPT
linux networking debian
  • 1 1 个回答
  • 188 Views

1 个回答

  • Voted
  1. Best Answer
    Biel
    2019-04-12T13:09:47+08:002019-04-12T13:09:47+08:00

    我的 iptables 规则确实有问题。我按照下一个脚本更改了它们(如果需要更改您的 ssh 端口,并添加您想要的规则):

    #!/bin/bash
    
    IPTABLES=/sbin/iptables
    
    echo " * flushing old rules"
    ${IPTABLES} --flush
    ${IPTABLES} --delete-chain
    ${IPTABLES} --table nat --flush
    ${IPTABLES} --table nat --delete-chain
    
    echo " * setting default policies"
    ${IPTABLES} -P INPUT DROP
    ${IPTABLES} -P FORWARD DROP
    ${IPTABLES} -P OUTPUT ACCEPT
    
    echo " * allowing loopback devices"
    ${IPTABLES} -A INPUT -i lo -j ACCEPT
    ${IPTABLES} -A OUTPUT -o lo -j ACCEPT
    
    ${IPTABLES} -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
    ${IPTABLES} -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    
    ## BLOCK ABUSING IPs HERE ##
    #echo " * BLACKLIST"
    #${IPTABLES} -A INPUT -s _ABUSIVE_IP_ -j DROP
    #${IPTABLES} -A INPUT -s _ABUSIVE_IP2_ -j DROP
    
    echo " * allowing ssh on port 22"
    ${IPTABLES} -A INPUT -p tcp --dport 34254  -m state --state NEW -j ACCEPT
    
    echo " * allowing ftp on port 21"
    ${IPTABLES} -A INPUT -p tcp --dport 21  -m state --state NEW -j ACCEPT
    
    echo " * allowing dns on port 53 udp"
    ${IPTABLES} -A INPUT -p udp -m udp --dport 53 -j ACCEPT
    
    echo " * allowing dns on port 53 tcp"
    ${IPTABLES} -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
    
    echo " * allowing http on port 80"
    ${IPTABLES} -A INPUT -p tcp --dport 80  -m state --state NEW -j ACCEPT
    
    echo " * allowing https on port 443"
    ${IPTABLES} -A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT
    
    echo " * allowing smtp on port 25"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
    
    echo " * allowing submission on port 587"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 587 -j ACCEPT
    
    echo " * allowing imaps on port 993"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 993 -j ACCEPT
    
    echo " * allowing pop3s on port 995"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 995 -j ACCEPT
    
    echo " * allowing imap on port 143"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 143 -j ACCEPT
    
    echo " * allowing pop3 on port 110"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 110 -j ACCEPT
    
    echo " * allowing mosquitto on ports 1883 and 8883"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 1883 -j ACCEPT
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 8883 -j ACCEPT
    
    echo " * allowing grafana on port 3000"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 3000 -j ACCEPT
    
    echo " * allowing node-red on port 1880"
    ${IPTABLES} -A INPUT -p tcp -m state --state NEW -m tcp --dport 1880 -j ACCEPT
    
    echo " * allowing ping responses"
    ${IPTABLES} -A INPUT -p ICMP --icmp-type 8 -j ACCEPT
    
    # DROP everything else and Log it
    ${IPTABLES} -A INPUT -j LOG
    ${IPTABLES} -A INPUT -j DROP
    
    #
    # Save settings
    #
    echo " * SAVING RULES"
    
    if [[ -d /etc/network/if-pre-up.d ]]; then
        if [[ ! -f /etc/network/if-pre-up.d/iptables ]]; then
            echo -e "#!/bin/bash" > /etc/network/if-pre-up.d/iptables
            echo -e "test -e /etc/iptables.rules && iptables-restore -c /etc/iptables.rules" >> /etc/network/if-pre-up.d/iptables
            chmod +x /etc/network/if-pre-up.d/iptables
        fi
    fi
    
    iptables-save > /etc/fwall.rules
    iptables-restore -c /etc/fwall.rules
    

    我现在仍然无法从我的 debian 服务器连接到我自己的 mosquitto 代理,但这可能是凭据问题。我从这里得到了这个脚本。

    • 0

相关问题

  • Win10 1803:如何让移动热点成为专用网络?

  • nc如何识别服务名称

  • 以 root 身份运行 docker 容器

  • 如何在域和 Linux 活动目录中启用指纹传感器

  • 如何在CentOS 7 中将Ctrl+C 永久更改为Ctrl+K?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve