Troubleshooting
MQTT client behind a remote access gateway cannot reach the broker
Short answer
Turning on internet access for LAN devices on a remote access gateway does not configure the client behind it. Set the MQTT client's default gateway to the gateway's LAN address and give it a DNS resolver when the broker is named by hostname. Then test in order: broker IP first, hostname second; an IP that connects while the name fails points at DNS, and neither connecting points at the route.

On this page
- What the internet access setting does and does not do
- Set the client's default gateway to the gateway's LAN address
- Give the client a resolver when the broker is named by hostname
- Tracing an edge PC at 192.168.1.50 that cannot reach a broker at 203.0.113.10
- Sort what remains into route, DNS, or MQTT
- The decision
- Questions asked
An MQTT client on the machine LAN behind a remote access gateway reaches a broker outside its own subnet only when the client itself is pointed at the gateway. Enabling the gateway's internet access for LAN devices opens the path; it configures nothing on the client. Two client settings decide the outcome: the default gateway, which must be the gateway's LAN address, and the DNS resolver, which matters as soon as the broker is named by hostname. This article works the failure from the client outward — what the internet access setting actually does, the settings to check, one worked address case, and how to tell a routing fault from a DNS fault from an MQTT fault.
What the internet access setting does and does not do #
Remote access gateways in this class are set up in a fixed order: internet access on the WAN side first, then a LAN address on the same subnet as the local devices the gateway serves. The internet access option shares the gateway's WAN connection with those LAN devices, normally through network address translation. That creates a path out. It cannot build the route table inside your client.
A client decides where to send each packet from its own settings, not from the gateway's. With no default gateway configured, the client delivers packets only within its own subnet, and a broker anywhere else is unreachable: the connect attempt times out. With the wrong default gateway, broker-bound packets go to a device that will not forward them, and the symptom is identical.
Four conditions must hold at once before MQTT connects through the gateway:
- Internet access for LAN devices is enabled on the gateway.
- The client's default gateway is the gateway's LAN address.
- The gateway's WAN side has a working route to the broker's network.
- The client has a reachable DNS resolver whenever the broker is configured by hostname.
A reply from the gateway itself proves only that the gateway is up; it says nothing about whether your packets leave it toward the broker — the same distinction drawn in this note on WAN ping being reachability, not LAN connectivity.
Set the client's default gateway to the gateway's LAN address #
The gateway's LAN address sits on the same subnet as the devices behind it, so on a machine LAN where the client holds, for example, 192.168.1.50, the gateway's LAN address is an address in that same 192.168.1.0 subnet. Read it from the gateway's LAN status page or its manual, then change the client:
- Open the client's IPv4 adapter properties (Windows) or its interface configuration (Linux).
- Set the default gateway field to the gateway's LAN address — 192.168.1.1 in the worked example below. The address must lie inside the client's own subnet; most TCP/IP stacks refuse to use a default gateway outside it.
- Verify on the client:
route printon Windows shows the gateway address on the default-route line, andip route showon Linux shows adefault vialine with that address. - Retry the MQTT connection.
Changing a default gateway tears down the client's established connections, so make the change in a planned window if the client is already serving the line. If that client must keep using the site router for everything else, leave its default gateway alone and add a host route for the broker's address through the remote access gateway instead — that points only broker-bound packets at the gateway.
Give the client a resolver when the broker is named by hostname #
A client reaches a broker by IP address with no DNS involved at all. The moment the broker is configured by hostname, the client needs a working resolver in its own TCP/IP settings, because correct routing does not resolve names, and a gateway that shares its internet connection is a router, not automatically a DNS server for the devices behind it.
The pattern that holds up in service: the site router or the plant DNS server as the client's primary resolver, with a public resolver such as 8.8.8.8 as the backup entry. If plant policy forbids public resolvers, resolve the broker's name through the plant DNS or another documented source instead of leaving the resolver field empty.
Test from the client: nslookup mqtt.example.com should return the broker's published address. If the lookup fails while a ping to the broker's address answers, the fault is DNS and not routing — the same failure shape as in why an MQTT app rejects a broker hostname and needs an IP address. The broker's own address can stay dynamic as long as DNS tracks it, which is a separate question from whether a local MQTT broker needs a static IP address. How resolvers are assigned across a plant network is its own design subject; this guide to DNS in industrial control systems covers hostname resolution for control-network devices.
Tracing an edge PC at 192.168.1.50 that cannot reach a broker at 203.0.113.10 #
Inputs for the case, all example values for a typical machine LAN:
- Client: an edge PC at 192.168.1.50 with netmask 255.255.255.0.
- Remote access gateway LAN address: 192.168.1.1, on the client's subnet.
- Broker: mqtt.example.com, resolving to 203.0.113.10, listening on TCP port 1883, the port the IANA service registry assigns to MQTT; 8883 is the MQTT-over-TLS port.
- Resolvers: the site router as primary, the public resolver 8.8.8.8 as backup.
The rule, in words: a host delivers a packet directly when the destination address AND the netmask equals its own network address; otherwise it hands the packet to its default gateway. The arithmetic:
- Client network: 192.168.1.50 AND 255.255.255.0 = 192.168.1.0
- Broker network: 203.0.113.10 AND 255.255.255.0 = 203.0.113.0
- 192.168.1.0 is not 203.0.113.0, so the broker is off-subnet and every broker-bound packet must be handed to the default gateway.
Result: with the default gateway field empty, the client has no path off its subnet and the MQTT connect times out. With the default gateway set to the gateway's LAN address and the backup resolver configured, the packets reach the broker and the client connects.
The tests that prove it, run on the client: ip route show lists default via the gateway's LAN address; ping 203.0.113.10 answers; nslookup mqtt.example.com returns 203.0.113.10; and a publish check such as mosquitto_pub -h mqtt.example.com -p 1883 -t plant/example/check -m ping completes without timing out.
Decision: any broker outside the client's own subnet makes a correct default gateway mandatory, and no setting on the gateway substitutes for it.
Sort what remains into route, DNS, or MQTT #
When the client settings are right, the failures left sort into three layers, and the test order tells you which one you are in:
| What you see on the client | Layer | Fix |
|---|---|---|
| Broker unreachable by IP on its port | Route | Default gateway missing or wrong; set it to the gateway's LAN address |
| Broker answers by IP, hostname does not resolve | DNS | Configure a resolver: site router or plant DNS first, public resolver as backup |
| Works from a laptop over the tunnel, not from the client | Test point | Run the tests on the client; the tunnel proves your path, not the client's |
| TCP connects, then the broker refuses or drops the client | MQTT application | Credentials, TLS certificate trust, or a duplicated client ID |
Two habits keep the diagnosis honest. Test from the client itself, because a laptop connected through the VPN exercises a different path than the device behind the gateway. And read a refused connection after a successful TCP handshake as progress: routing and DNS are proven, so move to the broker side — the client's credentials, the TLS certificate chain it trusts, and its client ID, which a broker rejects when another live connection already uses it. When the broker itself runs on a Windows PC, its listener binding and firewall add their own causes, covered step by step in why a device cannot publish MQTT to a broker on your PC.
The decision #
If the broker is outside the client's subnet — the normal case on a machine LAN — the client's default gateway must be the remote access gateway's LAN address, and nothing configured on the gateway replaces that setting. Diagnose in one order: broker IP first for the route, hostname second for DNS, publish last for the MQTT application layer. That order resolves every case in the table above.
Questions asked
Should the remote access gateway itself act as the client's DNS server?
Do not plan on it. Gateways sold for this role are documented as routers that share their internet connection with LAN devices, not as DNS servers for those devices, and undocumented behavior can change with a firmware update. Set the client's resolver to the site router or the plant DNS server, and when plant policy forbids public resolvers, put the broker's hostname in the client's hosts file so the name still resolves.
The VPN tunnel to the machine is up, so why can the client still not publish?
The tunnel proves your laptop reaches the machine LAN through the gateway; it says nothing about the client's own path out to the broker. A client sitting behind the gateway uses that gateway as its ordinary internet router and needs its own default gateway and resolver. Run the address, name and publish tests on the client itself rather than from a laptop connected over the tunnel.
Which ports does an MQTT connection use?
Plain MQTT uses TCP port 1883 and MQTT over TLS uses TCP port 8883. Confirm which listener the broker actually publishes, then check that the gateway's WAN firewall and any plant firewall in between allow that port outward. A blocked port looks identical to a missing route from the client side: the connection attempt simply times out.
Routing and DNS check out, but the broker still refuses the client. What is left?
The application layer. Check the client's username and password, that the client trusts the TLS certificate the broker presents, and that the client ID is not already in use, because a broker drops a new connection that duplicates a live client ID. Broker logs separate these quickly, since authentication failures, TLS handshake failures and client ID takeovers each log a different error.


