Mosquitto (on PI) only works in localhost


I am far from being a computer network specialist, but I learn a little bit at a time.
My goal is to dialogue between Arduino with MQTT via Mosquitto installed on a raspberry.
But if it works in localhost, this is not the case in the local network like for example with ‘MQTT Explorer’ on Windows or connection sketches in Arduino.
No way connect to the server. I disabled the firewall of the Asus RT-AC88u router and I do my Ethernet tests.
I installed it on another PI ‘virgin’ and I have the same problem.
It’s been a week that I turn around and lots of tutorials seem to copy each other but without examples or clear explanations.
Not to mention that I do not control English and that translators are sometimes approximate in the technical fields …

A big thank you in advance!

Hi Pollux,

I’m sorry to hear you’re having problems. I’m sure we can sort them out.

From Mosquitto version 2.0 onwards some of the way the broker works changed, which is why the tutorials you are looking at may miss some steps out I imagine.

If you run Mosquitto without a configuration file then it will allow unauthenticated access but on localhost only. The same is true if you have a configuration file but do not define a listener.

If you want to allow connections from other computers, you must define a listener and define some form of authentication. That could be password file based authentication, the dynamic security plugin, or allowing unauthenticated access with the allow_anonymous true option.

Once you’ve done one of those, the broker should work as you expect.

Some configuration examples:

# Completely unauthenticated
listener 1883
allow_anonymous true
# Dynamic security plugin
# Note that the paths may be different on your system
# Use mosquitto_ctrl or the Management Center to control the plugin
listener 1883
plugin /usr/lib/
plugin_opt_config_file /var/lib/mosquitto/dynamic-security.json
# Password and Access Control List file
# Use mosquitto_passwd to manage the password file
listener 1883
password_file /etc/mosquitto/passwd
acl_file /etc/mosquitto/acl

Let me know if that works or if you need more help.



Yes, another forum gave me a track and I understood the problem by visualizing the log. (“local only mode” …)

sudo tail -f /var/log/mosquitto/mosquitto.log | tee /var/tmp/mosquitto.log
1629960276: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1629960276: mosquitto version 2.0.11 starting
1629960276: Config loaded from /etc/mosquitto/mosquitto.conf.
1629960276: Starting in local only mode. Connections will only be possible from clients running on this machine.
1629960276: Create a configuration file which defines a listener to allow remote access.
1629960276: For more details see
1629960276: Opening ipv4 listen socket on port 1883.
1629960276: Opening ipv6 listen socket on port 1883.
1629960276: mosquitto version 2.0.11 running
1629962076: Saving in-memory database to /var/lib/mosquitto//mosquitto.db. 

Sure enough, with trial and error, I modified the configuration file, and it works by adding the lines as you have also suggested in your reply.

allow_anonymous true
listener 1883
protocol mqtt

Moreover, the site suggested in the log: “Authentication methods | Eclipse Mosquitto” is clear even to a francophone.
Good luck and thank you!