Troubleshooting
Node-RED MQTT shows connecting when the host cannot resolve
Short answer
When a Node-RED MQTT node sits on connecting and the runtime log shows an unknown-host error, the edge device cannot resolve the broker's hostname: ping a public name and the broker name from the device itself, then set the DNS server and default gateway its static configuration is missing. A desktop client connecting from a laptop proves credentials, not the device's path.

On this page
When a Node-RED MQTT node sits on connecting and the runtime log shows an unknown-host error, the edge device cannot turn the broker's hostname into an address, and no edit to the flow will fix that. Test the device itself before touching MQTT: from its own network diagnostics page, ping a public hostname such as google.com, then ping the broker hostname. If the public name also returns unknown host, the DNS server and default gateway are missing from the device's static configuration, and that is the whole fault. A desktop MQTT client connecting from a laptop proves the credentials are valid; it proves nothing about the device's resolver, its route, or the configuration the Node-RED runtime actually uses. Fix one device to a full connection, then copy the working settings.
Unknown host is a resolver result, not an MQTT fault #
An MQTT session is built in order: the runtime resolves the hostname to an address, opens a TCP socket to the broker port, sends CONNECT with the username and password, then subscribes and publishes. A node stuck on connecting with an unknown-host failure never finished the first step, so the broker, its port and the credentials were never reached.
Node.js reports that resolver failure in the log as getaddrinfo ENOTFOUND followed by the hostname, which is the signature of a DNS problem on the machine running Node-RED, not of a rejected password or an offline broker. The new session visible in the broker's account page belongs to the desktop client on the laptop, which has its own resolver and its own network path. Both facts point away from MQTT: the device never got far enough to fail at MQTT.
Test the device itself with two pings #
Use the device's own tools, across its own network connection. A laptop on the same bench is different hardware with a different path, so its results do not transfer.
- Open the device's web administration and find the network diagnostics page; edge devices and industrial PCs nearly always include a ping tool there. On a device with shell access,
ping -c 3 google.comdoes the same from the console. - Ping a public hostname such as google.com first. This separates name resolution from broker behavior, because some brokers drop ping entirely while a public web host answers.
- Ping the broker hostname exactly as it appears in the broker configuration node.
- Write down both results before changing anything.
Each outcome selects its own branch:
- Public hostname returns unknown host: the device cannot resolve any name. The DNS server or the default gateway is missing or wrong in its static configuration. Fix that first; MQTT is not involved yet.
- Public name resolves and answers, broker hostname returns unknown host: resolution works, so the broker name is misspelled in the configuration node, or the configured DNS server has no record for a name it was never meant to see.
- Both names resolve, the public host answers, the broker does not answer ping: not yet a fault, because a broker may suppress ping. The flow's connection attempt is the application-level test.
- Both names resolve and both hosts answer: resolution and routing are good. Go straight to the Node-RED checks.
When the broker sits across a routed plant network instead of the internet, the same two pings decide whether the device has a usable path at all; the remaining failure points along that path are covered in why an edge gateway cannot connect to your MQTT broker.
Fix the static network configuration #
A static IP address by itself is an incomplete configuration. Any destination outside the device's own subnet needs a default gateway, and any hostname needs a DNS server; a setup that entered only the address and mask produces the same unknown-host failure for every name the device tries.
Fill the two missing entries on the interface that faces the upstream network:
- Default gateway: the upstream router's address on the device's own subnet.
- DNS server: the resolver the network actually provides, meaning the router's address if it forwards DNS, a plant-internal resolver, or for example 8.8.8.8 where outside DNS is permitted.
On a device with two ports the mapping matters. If the modem or upstream switch hangs on eth1 and the bench laptop on eth0, the gateway and DNS belong to eth1's configuration; entering them on the laptop-facing port leaves the upstream route empty, which is exactly how this fault survives a check that looked right. If the upstream network runs DHCP and site policy allows it, switching that interface from static to dynamic picks up gateway and DNS automatically; a static setup is equally correct once both entries are filled.
Make the change in a maintenance window: while the address settings are edited and applied, the device's route drops, and any remote-access session to it drops with it.
Apply the settings and repeat the two pings before opening Node-RED.
Worked example: 192.168.1.50 on a /24 reaching a cloud broker #
The case is a typical static setup of the kind that produces this fault; the values are examples, since a failing screen of this kind shows an address and mask but empty resolver fields.
- Device address: 192.168.1.50 with mask 255.255.255.0, a /24 with 254 usable addresses.
- Broker hostname: mqtt.example.com, which a working resolver would return as 203.0.113.10, an address from the reserved documentation range used here so that no real host is implied.
- DNS server field: empty. Default gateway field: empty.
Two rules decide the outcome. First, resolution precedes everything: no packet exists until the hostname becomes an address. Second, the device compares the destination with its own subnet: a destination inside its /24 is delivered directly on the wire, and anything else is handed to the default gateway.
Apply the mask to both addresses:
- 192.168.1.50 AND 255.255.255.0 = 192.168.1.0, the device's own network.
- 203.0.113.10 AND 255.255.255.0 = 203.0.113.0, the broker's network.
- 192.168.1.0 does not equal 203.0.113.0, so the broker is off-link.
Two independent failures follow. The empty DNS field means mqtt.example.com never becomes an address, so the runtime logs the resolver error and the node shows connecting; no packet was ever built. Even with the broker's address entered directly, the empty gateway means there is no route to 203.0.113.0/24, so the socket attempt times out.
The decision: any broker address outside 192.168.1.1 through 192.168.1.254 needs both entries, the gateway set to the upstream router on that subnet, for example 192.168.1.1, plus a reachable DNS server. Fill both and the same arithmetic flips: the name resolves, the comparison sends the packet to the gateway, and the session proceeds. A broker genuinely on-link, say 192.168.1.10, needs a DNS record for its name but no gateway. Substituting the address for the name is a one-minute diagnostic, not a repair: it hides a broken resolver and breaks certificate checks that expect the broker's hostname. The case where an address really is required, and when the hostname must win instead, is laid out in why an MQTT app rejects a broker hostname and needs an IP address.
Return to the flow only after the pings pass #
With both pings passing, the remaining checks are ordinary configuration. Open the MQTT in or out node and open its broker configuration node from there, then confirm three things:
- The hostname is spelled exactly as the broker service issued it. A desktop client's successful session validates the username and password only if it dialled the same hostname.
- The flow points at the right configuration node. Configuration panels accumulate duplicates from earlier edits, and a flow can keep pointing at one that still carries the old hostname; count the broker nodes in the panel and reselect the current one.
- The protocol matches the broker. Some services accept only legacy MQTT 3.1; the broker configuration node has a legacy-mode checkbox, cleared by default. Select it, deploy, and watch the status. Treat it as a compatibility test rather than a confirmed root cause, and clear it again if the status does not change.
Deploy after each change; the status flag under the node shows every attempt. If the pings pass, the hostname and credentials match the desktop client's settings, and the broker still refuses the session, the rejection is broker-side rather than device-side: see Node-RED MQTT fails when the broker rejects plain MQTT for that branch.
Verify the repair in order #
- The public hostname resolves and answers: resolution and routing work from this device.
- The broker hostname resolves. A broker that drops ping still passes this step; the flow is the application test for reachability.
- After a deploy, the node's status leaves connecting.
- The broker's account page records the device's session, timed with the deploy you just made.
The results decide the branch. If step 1 fails, the fault is still DNS or gateway. If step 2 fails while step 1 passes, the hostname spelling or the chosen resolver is wrong. If steps 1 and 2 pass but step 3 fails, work the credentials and protocol checks in the flow; the network work is done. Once all four hold, apply the same settings to the second device, redeploy there, and expect the same four results.
Questions asked
The broker account shows a new connection while Node-RED still says connecting. Which client made it?
Almost always the desktop MQTT client on the laptop. A broker counts every successful session, and the laptop has its own resolver, its own route and working DNS, so its session appears in the account page even while the edge device fails. That connection proves the hostname, username and password are valid from the laptop. It says nothing about the device, which never opened a socket.
How do I tell a DNS fault from a gateway fault on the device?
Ping an address and then a name from the device itself. If ping 8.8.8.8 answers but ping google.com returns unknown host, the route and gateway work and only the DNS entry is wrong. If the numeric ping also fails, the device has no working route: check the gateway field, the interface cabling toward the upstream router, then the DNS entry.
Can I enter the broker's IP address in the configuration node instead of fixing DNS?
It will make the socket connect, because no lookup is needed, and it is useful as a one-minute diagnostic. It is not a repair: the resolver stays broken for every other hostname, TLS certificate checks that expect the broker's hostname can fail, and the entry breaks again when the provider changes addresses. Fix the DNS entry and keep the hostname.
Why did this flow work two weeks ago and fail today without any change?
The flow did not change; the path under it did. Typical causes: the modem or router was replaced or re-addressed, the subnet moved so the static gateway no longer exists, the DNS server the device pointed at disappeared, or the device was reimaged and its static entries were never re-entered. The two ping tests show which link moved.
What does an unknown host error actually mean here?
The device's resolver had no DNS server to ask, or asked and got no answer, so the hostname never became an address. The MQTT client therefore never opened a socket: no broker, port, username or password was involved yet. The failure sits at operating-system level, which is why the fix lives in the network settings rather than in the flow or the broker.

