Updated: May 25, 2017

Quick Guide to The Mosquitto.conf File With Examples

mosquitto-conf-iconYou can configure the mosquitto broker using a configuration file.

The default configuration file is called mosquitto.conf and it is used by the mosquitto broker when started as a Linux daemon or Windows service.

You will find the mosquitto.conf file in the /etc/mosquito directory on Linux, and in the c:\mosquitto\ directory on Windows.

Note: the Windows install lets you choose the directory.

Important: In order for changes in the mosquitto.conf file to become effective you must restart the mosquitto broker.

Broker Mosquitto.conf Settings

The default mosquitto.conf file has all of the settings commented out and the broker doesn’t require a configuration file to run.

If you look at the settings you will find that they are divided into sections and some of the settings affect the entire broker instance, whereas others affect a particular listener.

A listener is effectively an additional port, and not an additional broker!

The diagram below is my understanding of how the settings apply.


Configurations Examples

Mosquitto Broker Listening on Several Ports

The mosquitto broker can be configured to listen on several ports at the same time.

However this configuration doesn’t mean that you have virtual brokers. as most of the configuration is shared.

You cannot, for example, configure a broker to listen on port 1884, and to allow anonymous access, and also to listen on port 1885 and not allow anonymous access.

Because they are part of the same broker instance they share the allow_anonymous setting.

However you can configure a broker to listen on a port and require SSL and also to listen on another port and not use SSL.

Example 1- Listen on ports 1883 and 1884

Section Default listener

port 1883

Section Extra listeners

port 1884

Example 2- Listen on ports 1883 and 8883 (SSL)

Section Default listener

listener 1883

Section Extra listeners

listener 8883

Certificate based SSL/TLS support

cafile c:\mosquitto\certs\ca.crt
keyfile c:\mosquitto\certs\server.key
certfile c:\mosquitto\certs\server.crt


cafile /etc/mosquitto/certs/ca.crt
keyfile /etc/mosquitto/certs/server.key
certfile /etc/mosquitto/certs/server.crt

Example 3- Listen on ports 1883 and WebSockets (SSL)

Section Default listener

listener 1883

Section Extra listeners

listener 9001
protocol websockets

See Also MQTT and Mosquitto WebSockets Working Notes

Starting Mosquitto – Notes

When starting mosquitto for the command line unless you specify a configuration file none is used. Therefore

mosquitto -v

and other similar commands start mosquitto without using a configuration file.

If you install mosquitto as a service on Windows then it starts using the mosquitto.conf.

The Linux install also configure the Mosquitto broker to start automatically using the mosquitto.conf file..

Important: When testing mosquitto you need to stop the mosquitto instance that has been started when the machine booted, and then start your own instance from the command line.

Editing The File- Tips

You can use a normal text editor to edit the file. Although it is tempting to edit the particular section of the file it can be very difficult finding what settings you have changed.

Therefore put all of your settings at the top of the file, and use the commented out section as documentation.

If you do edit the individual sections then I have created a simple Python script that will display only the uncommented settings from the file.

Running Multiple Mosquitto Brokers

You can configure a broker to listen on several ports, but to create multiple brokers with their own configurations then you will need to start multiple instances of mosquitto.


Start mosquitto and listen on port 1883

mosquitto -p 1883

Start mosquitto as a daemon and listen on port 1884

mosquitto -p 1884 -d

Start mosquitto as a daemon and use the mosquitti-2.conf file. –  Windows

mosquitto -c c:\mosquitto\mosquitto-2.conf  -d

or Linux

mosquitto -c /etc/mosquitto/mosquitto-2.conf  -d

Useful Linux Commands

To stop Mosquitto when running as a daemon:

ps -aux | grep mosquitto
pgrep mosquitto
kill -9 PID (that you get from above command)


Mosquitto.conf Manual Page

Related Tutorials

Please rate? And use Comments to let me know more
[Total: 3    Average: 4.3/5]

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *