OPNsense Forum

English Forums => 25.1, 25.4 Production Series => Topic started by: endophilius on April 26, 2025, 01:26:11 AM

Title: NAT not working with MQTT
Post by: endophilius on April 26, 2025, 01:26:11 AM
Hello everyone,

I'm running OPNsense on an amd64-machine with version 25.1.5_5. About half a year ago I set up NAT Port Forwarding for mosquitto on port 1883 (standard MQTT port). It worked until lately I noticed that my MQTT client outside of my network can't reach mosquitto anymore.

My network structure is:


What I tried:


There seem to be a few connectivity issues between the FRITZ!Box and my OPNsense as I also can't reach some outer services from inside my OPNsense. Thinking of some kind of disk issue or so I reinstalled the OS to another disk and restored a backup which was made at a time when the MQTT rule worked. But even this didn't do what it' supposed to, but restored everything correctly.

I'm running out of ideas what the problem could be and what I can do to find it. Do you have any ideas what could cause the NAT connection to be blocked or not correctly forwarded/routet?

Thanks for every reply :-)
Title: Re: NAT not working with MQTT
Post by: EricPerl on April 26, 2025, 03:34:47 AM
Given your setup (OPN behind another stateful FW), I assume you've disabled reply-to (in Firewall > Settings > Advanced).
Title: Re: NAT not working with MQTT
Post by: endophilius on April 26, 2025, 01:06:06 PM
Thanks for the reply. I checked the option and I havn't checked 'Disable reply-to' so the reply-to on WAN rules should be enabled.

I also enabled NAT reflection. With that I can access mosquitto from within my local network when going through 192.168.178.69 so the NAT is correctly reflected, but it depends on where the traffic comes from. If it comes from LAN, it goes through, if it comes from WAN it is blocked.
Title: Re: NAT not working with MQTT
Post by: Patrick M. Hausen on April 26, 2025, 01:38:53 PM
If the client is in the same network as the WAN interface you must check that "Disable reply-to" box.
Title: Re: NAT not working with MQTT
Post by: EricPerl on April 26, 2025, 10:09:18 PM
https://docs.opnsense.org/manual/firewall_settings.html#disable-reply-to (https://docs.opnsense.org/manual/firewall_settings.html#disable-reply-to)

Per the first part of the warning, with the setting unchecked, replies out from OPN WAN will be directed to the GW for that network (your fritzbox) where they likely get blocked/ignored because the requests did not flow this way.
Title: Re: NAT not working with MQTT
Post by: endophilius on April 28, 2025, 12:39:48 PM
I now checked this option and disabled the reply-to. I also waited to mitigate a possible blacklist/graylist on my FRITZ!Box. Until now the connection can't be established and the symptoms are the same as with the option unchecked.
Title: Re: NAT not working with MQTT
Post by: EricPerl on April 28, 2025, 08:56:56 PM
The Fritzbox shouldn't be used at all in this scenario (potential exception if it acts as a switch in between the hosts).
Communication between the client and OPN.WAN is on the same subnet.
In other words, this should no longer be the case:
QuoteTest if OpenDTU makes requests or if the FRITZ!Box blocks them
  - I can see the requests im my firewall log so they must have been sent and are passed by my primary gateway.

There should be no 10.xxx traffic on the Fritzbox networks (OPN.WAN side) so this is useless:
QuoteIs the routing between the FRITZ!Box and my OPNsense correct?
  - Yes, even though I'm pointing to 192.168.178.69 in OpenDTU, I also set my OPNsense as the gateway for 10.0.0.0/8 in the 192.168.178.0/24 network.
  - This also works, traffic is correctly routed.

Anyway, at this point, it's probably time to do a packet capture (WAN + LAN) to see where the flow stops.
You can filter by port and IP (client or server) based on usage in your network.

That's how I figured out something was wrong on my internal router.
Packets out of WAN (reply back to client) had the MAC of my edge router LAN... They should have had the MAC of the client.
Title: Re: NAT not working with MQTT
Post by: endophilius on May 07, 2025, 08:16:39 PM
Hi everyone,

sorry that I didn't respond for so long, I had some other things intercepting.

Now I did the packet capture and it seems like the OPNsense is not responding the the SYN the OpenDTU sends. I have attached the .pcap below (and I am aware of the privacy risk it brings with it but I'm okay with that).
Title: Re: NAT not working with MQTT
Post by: EricPerl on May 07, 2025, 11:15:39 PM
That's only the WAN side. It establishes that OpenDTU tries to open a connection.

If the LAN side was included, we'd see if the frame is properly forwarded (from OPN.LAN.Address to the server).
And we'd also see if we were getting a reply (assuming the filtering is appropriate).

As of now, I can't tell where the traffic stops...
Title: Re: NAT not working with MQTT
Post by: endophilius on May 08, 2025, 10:40:13 AM
The packets also go through at the LAN side. They even can reach the server-host but not the docker-container that is running on the server. But this is not an OPNsense problem, so I'll ask at other places that are more specific to my issue.

Thank you for your help!