I am new to Mosquitto; I have used the HiveMQ MQTT broker successfully but need to set up Mosquitto MQTT broker for a specific test.
I am trying to get multiple PCs and a PLC talking to my broker across a simple switch.
My broker only seems to be bonded to the localhost, not the physical IP address of my PC hence the external PCs and PLC cannot connect.
This fails with the config file unedited. I have tried various edits to the config file but always get the same failed result. Does anyone know how I can achieve this very basic setup or where I could find any documentation on it?
Can you share a little more context?
The Broker is available via many different sources and this can impact the behavior.
E.g. if you are using Mosquitto via docker, it is important to bind ports.
I downloaded it from: Download | Eclipse Mosquitto
I made some progress: my MQTT app on my laptop can now connect to a server on my laptops IP address. Needed to add lines for listener then run a command to force it to use the config file (sent to me by support, cant seem to find any documentation mentioning these…):
Now my problem is my main PC cannot connect to the Mosquitto server on the same IP address. If I stop Mosquitto and start up HiveMQ on my laptop, my main PC can connect fine so it is unlikely network related.
Now that I’ve bound Mosquitto to my laptops IP address, how do I make the broker externally available?
One info, which would be interesting to know would be the operating system you use (Windows or Linux).
In general the mosquitto installation packages normally install the broker to run as a daemon (respective service on windows). So starting the broker manually will not really work in this case as the broker running in the background will block the default port 1883 on localhost and raise a conflict. If you want to start a broker manually you first would need to stop the daemon/service.
If you want to modify the daemon/service behavior you would need to modify the config file in the default location (this is different for windows/linx and restart the daemon service.
On modern operating systems active software firewalls (ufw for linux, integrated FW for windows) may block access to the broker as well.
You may find some starter guides either on our company webpage or on other paces (e.g steves internet guide).
Feel free to get back, if you need further help. Some additional information like the operation system used and log/output of the broker start will be very helpful in this case.
So to confirm, the daemon should start running automatically when I start my PC?
Then I stop the daemon using task manager and start it again by double clicking the .exe file in the install folder?
Please find the log output it gave me during start-up. It is recognizing the client on the same PC as the broker, but my other PC cannot connect even though it can ping:
1692904462: mosquitto version 2.0.15 starting
1692904462: Config loaded from mosquitto.conf.
1692904462: Opening ipv4 listen socket on port 1883.
1692904462: mosquitto version 2.0.15 running
1692904462: New connection from 192.168.1.7:62857 on port 1883.
1692904462: New client connected from 192.168.1.7:62857 as mqtt-explorer-fc61c047 (p2, c1, k60).
1692904462: No will message specified.
1692904462: Sending CONNACK to mqtt-explorer-fc61c047 (0, 0)
1692904462: Received SUBSCRIBE from mqtt-explorer-fc61c047
1692904462: /TEST/# (QoS 0)
1692904462: mqtt-explorer-fc61c047 0 /TEST/#
1692904462: Sending SUBACK to mqtt-explorer-fc61c047
1692904462: Received SUBSCRIBE from mqtt-explorer-fc61c047
1692904462: MQTT_DATA_INT (QoS 0)
1692904462: mqtt-explorer-fc61c047 0 MQTT_DATA_INT
1692904462: Sending SUBACK to mqtt-explorer-fc61c047
1692904462: Received SUBSCRIBE from mqtt-explorer-fc61c047
1692904462: MQTT_DATA_INT.Value (QoS 0)
1692904462: mqtt-explorer-fc61c047 0 MQTT_DATA_INT.Value
1692904462: Sending SUBACK to mqtt-explorer-fc61c047
1692904462: Received SUBSCRIBE from mqtt-explorer-fc61c047
1692904462: # (QoS 0)
1692904462: mqtt-explorer-fc61c047 0 #
1692904462: Sending SUBACK to mqtt-explorer-fc61c047
1692904462: Received SUBSCRIBE from mqtt-explorer-fc61c047
1692904462: test/topic (QoS 0)
1692904462: mqtt-explorer-fc61c047 0 test/topic
1692904462: Sending SUBACK to mqtt-explorer-fc61c047
1692904522: Received PINGREQ from mqtt-explorer-fc61c047
1692904522: Sending PINGRESP to mqtt-explorer-fc61c047
Hi Rob,
sorry for the late response. Services in WIndows are similar to daemons in Linux and will be monitored by the OS and restarted, if you simply stop them from the task manager. To be able to start a broker manually using the same config/port as the service you would need to stop the service in the Windows service control panel. And to prevent a start at the OS start you would need to disable the service.
I had the same issue - I could only connect on localhost until I made those same changes to the config that comes out of the box.
This forum post thread led me in the right direction though, thanks!
I did manage to find quite a bit of documentation for future reference …
The specific issue of lifting the localhost restriction and general security concerns are addressed at the bottom of this page:
After you have installed and started the Mosquitto Docker container, the broker will be listening at the following address The default configuration file is called mosquitto. conf and it is used by the mosquitto broker when slope unblocked started as a Linux daemon or Windows service. You will find the mosquitto. conf file in the etc mosquitto directory on Linux, and in the c:\mosquitto directory on Windows.