我的 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
我的 iptables 规则确实有问题。我按照下一个脚本更改了它们(如果需要更改您的 ssh 端口,并添加您想要的规则):
我现在仍然无法从我的 debian 服务器连接到我自己的 mosquitto 代理,但这可能是凭据问题。我从这里得到了这个脚本。