IMD SolutionComputing LibraryShop main store

Troubleshooting

Why an edge gateway cannot connect to your MQTT broker

Edge computing and IIoT Published 6 min read By IMD Solution engineering team

Short answer

If an edge gateway cannot connect to your MQTT broker while local clients work, the usual cause is Mosquitto 2.0 or newer running in local-only mode: it accepts connections from its own host until you define a listener on all interfaces with authentication set. An open firewall rule for the MQTT port and successful pings to the gateway prove neither that the broker listens on the LAN interface nor that the gateway can reach it.

On this page
  1. Why does MQTT work on localhost but fail from the edge gateway?
  2. Why does opening TCP 1883 in the firewall not fix it?
  3. How do you tell what the broker is actually listening on?
  4. What has to change in the broker configuration?
  5. Do ping and Telnet to the gateway prove the MQTT path works?
  6. Is the gateway on the same subnet as the broker?
  7. How do you confirm the broker accepted the gateway?
  8. Questions asked

An edge gateway that cannot connect to your MQTT broker while the same broker works from a local client is being refused by the broker itself far more often than by the network. Since version 2.0, Mosquitto starts in local-only mode unless its configuration defines a listener: it accepts clients on its own host and turns every other client away, so the firewall rule for the MQTT port and the successful ping to the gateway both test conditions that never decide this case. Work through the broker listener first, the address second, and read the verdict in the broker log.

Why does MQTT work on localhost but fail from the edge gateway? #

Because a localhost connection only proves the broker process is running on that machine: Mosquitto 2.0 and newer start in local-only mode and accept clients from the broker host alone, so the gateway is refused before your firewall rule for TCP 1883 is ever consulted.

The broker is not broken; it is doing exactly what an unconfigured Mosquitto 2.0 does. Every test you run from the broker PC passes because that traffic never leaves the machine, and every remote client fails because no listener exists for it. Once you see the split this way, the fix is a broker configuration change, not a network hunt.

Why does opening TCP 1883 in the firewall not fix it? #

A firewall rule and a broker listener are two separate conditions: the rule only decides whether packets may reach the host, while the listener decides whether any process on that host answers them, so opening the port cannot make the broker accept a remote client.

Both conditions must hold at once. The firewall rule you set was correct but incomplete; it answered the question the network layer asks while the broker was still failing the question the application layer asks. Keep the rule, and add the listener it was supposed to expose.

How do you tell what the broker is actually listening on? #

Read the broker's startup output or ask the operating system which address and port the broker process holds: a log line announcing local-only operation, or a socket bound to the loopback address instead of 0.0.0.0, means remote clients have no listener to reach.

Two checks, and they should agree. The broker's own startup output is authoritative: an unconfigured Mosquitto 2.0 prints a banner that begins with local-only mode and states that connections will only be possible from clients running on that machine. Second, list the listening sockets with your operating system's socket utility, ss -ltnp on Linux or netstat -ano on Windows, and read the local address for the MQTT port: 127.0.0.1:1883 serves that machine only, 0.0.0.0:1883 serves every interface. If the firewall rule is open but the socket still shows the loopback address, you have found the fault.

What has to change in the broker configuration? #

A listener bound to all interfaces together with an explicit authentication setting: since version 2.0 Mosquitto stays local-only without a listener directive, and once a listener exists the broker requires you to decide who may connect, so both lines go in as a pair.

For a plant network, the minimum working pair in the broker configuration looks like this:

listener 1883 0.0.0.0
allow_anonymous false

The listener line makes the broker answer on TCP 1883 on every interface, and allow_anonymous false rejects any client that has no credentials, so create gateway credentials with the broker's password utility and name that credentials file in the same configuration. On an isolated, non-production bench, allow_anonymous true is the shortcut; never on a network that touches the plant.

Then apply and verify in this order:

  1. Add the listener line bound to 0.0.0.0.
  2. Set the authentication line and the credential file together.
  3. Restart the broker service so the new configuration takes effect.
  4. Re-check the socket list and confirm the broker now holds 0.0.0.0 on the MQTT port.
  5. Connect the gateway and read the broker log for the connection record.

Do ping and Telnet to the gateway prove the MQTT path works? #

No: a successful ping or Telnet session to the gateway tests traffic from the broker PC toward the gateway, the opposite direction of the MQTT connection you are troubleshooting, so it proves nothing about whether the gateway can open the MQTT port to the broker.

The evidence so far sorts cleanly once you write down which direction each test travels:

Test you ran Direction it proves What it cannot prove
MQTT works from a client on the broker PC the broker process runs that remote clients are accepted
Firewall rule open for the MQTT port the host passes inbound traffic on that port that a listener holds the port
Ping and Telnet to the gateway succeed the broker PC reaches the gateway that the gateway reaches the broker
Broker log shows a connection from the gateway address the whole path, both directions nothing further

The one test that means something runs from the gateway side: an MQTT client on the gateway, or at least a connection attempt to the broker address on the MQTT port from the gateway's own shell. If TCP connects and MQTT still fails, the next layer down is the handshake itself, and MQTT connect fails when TCP works: diagnose the handshake walks that check end to end.

Is the gateway on the same subnet as the broker? #

Usually yes, and one line of mask arithmetic settles it: a broker at 192.168.1.50 and a gateway at 192.168.1.77 under netmask 255.255.255.0 both reduce to network 192.168.1.0, so the gateway reaches the broker directly with no router in between.

Work it the way the operating system does, as a bitwise AND of address and netmask:

  • 192.168.1.50 AND 255.255.255.0 = 192.168.1.0, the broker's network
  • 192.168.1.77 AND 255.255.255.0 = 192.168.1.0, the same network, so the gateway reaches the broker directly and no router applies its own rules
  • 192.168.2.77 AND 255.255.255.0 = 192.168.2.0, a different network, so the gateway's traffic needs a router, and that router needs its own rule for the MQTT port

These addresses are an example; substitute your own and the arithmetic still decides. Check the address in the gateway's broker field too: it must be the broker host's LAN address, for example 192.168.1.50, never a loopback name. That addressing slip is the same fault behind an MQTT sink that stays offline until you use the broker IP address, and if the choice between a fixed address and a hostname is the open question, whether a local MQTT broker needs a static IP address covers it.

How do you confirm the broker accepted the gateway? #

At the broker, never only on the gateway: the log must record a new client connection from the gateway's address and a test message must arrive on a subscription, because a connected indicator on the gateway can outlive a session the broker has already closed.

Subscribe from any trusted client to a test topic, publish one message from the gateway, and look for both the connection record and the message at the broker. If the attempt still fails, the broker's own rejection or timeout output names the layer that failed: a refusal at connection time points at the listener or authentication you just changed, while silence points back at the network path.

The decision for each case: local clients work and remote ones fail, fix the broker configuration first — add the listener on all interfaces, set authentication, restart, and expect a connection record from the gateway address in the broker log within seconds. TCP connects but MQTT fails, move to the handshake. Nothing answers at all, check the subnet arithmetic and the path between the two devices. The firewall rule you already opened was never wrong to have; it was simply never the condition that failed.

Questions asked

Which log line shows that Mosquitto started in local-only mode?

At startup an unconfigured Mosquitto 2.0 broker prints a banner that announces local-only mode and states that connections will only be possible from clients running on that machine. If the startup output instead lists a listener with an address and port, remote clients have something to connect to and the fault lies elsewhere.

Does a TLS listener need a different setup than the plain one?

The listener declaration works the same way, but a TLS listener uses TCP 8883 instead of 1883 and must name the broker certificate and its private key in the configuration. The firewall and the client trusted CA list must cover that port too; opening the plain port does nothing for a TLS-only listener.

What is the difference between connection refused and a connection timeout?

Connection refused means the host answered and nothing accepted the connection on that port, which points at a missing listener or a broker process that is down. A timeout means no answer at all, which points at a firewall dropping packets, a wrong address in the gateway, or a missing route between the gateway and the broker.

Why did my broker change behavior after an update?

Mosquitto changed its default at version 2.0: installations that relied on the old default, which accepted remote clients without a listener, suddenly start in local-only mode after the upgrade. Adding a listener and an authentication setting restores remote access, which is why a broker upgrade is the most common moment this fault appears.

Keep reading

  • Troubleshooting

    Fix a PLC MQTT client that never reaches your broker

    Most PLC MQTT failures sit in one of three stages: the broker listener, the network path to the port the client is actually configured for, or the client's own publish logic. Test in that order; a connect timeout points to the first two, a silent publish to the third.

    Edge computing and IIoT

  • Troubleshooting

    Why a device cannot publish MQTT to a broker on your PC

    Point the device's client at the PC's LAN address, not 127.0.0.1 — loopback always means the device that opens the connection. Then confirm the broker listener is bound to the PC's LAN interface on TCP 1883 and that Windows Firewall admits inbound connections on that port from the plant subnet. Fix those three and the publish path works.

    Edge computing and IIoT

  • Troubleshooting

    Why Mosquitto 2.0 rejects a Telegraf MQTT output: identifier rejected

    A Telegraf v1.19.3 MQTT output that works against Mosquitto 1.5 but fails against 2.0.12 with identifier rejected is sending a keepalive of zero: the plugin hard-codes it, and Mosquitto 2.x refuses an unlimited keepalive. MQTT 3.1.1 has no server-assigned keepalive, so the refusal leaves as CONNACK return code 2. Give the client a nonzero keepalive, by upgrading Telegraf or patching the line, and keep the 2.0.12 broker.

    Edge computing and IIoT