# Cannot connect to mosquitto MQTT Broker

**URL:** <https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807>\
**Category:** General\
**Tags:** mqtt\
**Created:** [7 July 2022 21:20 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807 "2022-07-07T21:20:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolasg12](https://avatars.discourse-cdn.com/v4/letter/n/dbc845/32.png) [@nicolasg12](https://discourse.nodered.org/u/nicolasg12)\
**Post date:** [7 July 2022 21:20 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/1 "2022-07-07T21:20:47Z")

</div>

Hello,

I have been learning node red for the past days and I wanted to start working with MQTT. For this I installed Mosquito on my Mac and created an MQTT broker. I know it works since I can play with it in the terminal using mosquitto\_pub and mosquitto\_sub, but when I try to connect to the broker using bordered it cannot connect.  
I use the localhost:1883 (I checked and this is the port where my broker is)

Can anyone help me please? anything can help, I have read that I need to edit the conf file from mosquitto but I don't know how to do that either.

Thank you in advance

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 July 2022 21:59 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/2 "2022-07-07T21:59:54Z")

</div>

In the mqtt nodes, you need to define the location of the broker. If you install the broker on device A (let's say it's IP address is 192.168.1.50) and NR is installed on device B (let's say it's IP address is 192.168.1.75), in the MQTT configuration you need to enter 192.168.1.50 as the server address

 ![Screen Shot 2022-07-07 at 5.47.47 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/891da8e307db52990143fab049c10968731e1b7e.png)

If your network knows about the device names you can use the device name in the server entry like mqttpizw.local (this is a pi zero w that I'm running mosquitto on)

---

<div class="post-metadata">

**Author:** ![nicolasg12](https://avatars.discourse-cdn.com/v4/letter/n/dbc845/32.png) [@nicolasg12](https://discourse.nodered.org/u/nicolasg12)\
**Post date:** [7 July 2022 22:07 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/3 "2022-07-07T22:07:51Z")

</div>

I have both (node red and mosquitto) running on the same device, if this is the case I should be able to connect using localhost right?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [7 July 2022 23:52 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/4 "2022-07-07T23:52:26Z")

</div>

I’m not sure since I’ve never done it. You can take a dive into the mosquito configuration documentation if you want.

> **[mosquitto.conf man page](https://mosquitto.org/man/mosquitto-conf-5.html)**
>
> Name
> mosquitto.conf — the configuration file for mosquitto
> 
> 
> Synopsis
> mosquitto.conf 
> 
> 
> Description
> mosquitto.conf is the configuration file for
> mosquitto. This file can reside anywhere as long as m

Check out the ‘bind\_address’ option.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [8 July 2022 00:22 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/5 "2022-07-08T00:22:32Z")

</div>

As @zenofmud said you need some configuration for the mosquitto broker to accept connections

I found a post on the forum about it where, since mosquitto version 2, some security settings need to be added :

```auto
allow_anonymous true
listener 1883

```

restart the brocker and also check if anything else (firewall?) is blocking the connection

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [8 July 2022 00:48 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/6 "2022-07-08T00:48:56Z")

</div>

> [@nicolasg12](#):
>
> bordered it cannot connect.  
> I use the localhost:1883 (I checked and this is the port where my broker is)
> 
> Can anyone help me please? anything can help, I have read that I need to edit the conf file from mosquitto but I don't know how to do that either.
> 
> Thank you in advance

So are you saying you have installed NodeRed natively on the Mac also ? And Mosquitto also - not in Docker containers ?

Craig

---

<div class="post-metadata">

**Author:** ![nicolasg12](https://avatars.discourse-cdn.com/v4/letter/n/dbc845/32.png) [@nicolasg12](https://discourse.nodered.org/u/nicolasg12)\
**Post date:** [8 July 2022 11:31 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/7 "2022-07-08T11:31:14Z")

</div>

Hi,  
I am running both in docker containers

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 July 2022 11:56 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/8 "2022-07-08T11:56:25Z")

</div>

> [@nicolasg12](#):
>
> docker containers

You can't use localhost from a docker container. You must use the ip of the mosquito container.

---

<div class="post-metadata">

**Author:** ![nicolasg12](https://avatars.discourse-cdn.com/v4/letter/n/dbc845/32.png) [@nicolasg12](https://discourse.nodered.org/u/nicolasg12)\
**Post date:** [8 July 2022 12:09 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/9 "2022-07-08T12:09:08Z")

</div>

I got the IP for the container and it still didn't work... also, if I try to connect with Mqtt explorer, I use localhost and it works just fine, I don't understand ☹

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [8 July 2022 12:16 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/10 "2022-07-08T12:16:46Z")

</div>

The two docker containers have their own IP address. To connect from one docker container to another docker container, you need to use the IP address of the second container. Also, as mosquito V2 is more secure by default, you need to edit the conf file to permit external connections other than localhost.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [10 July 2022 02:25 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/11 "2022-07-10T02:25:36Z")

</div>

> [@nicolasg12](#):
>
> Hi,  
> I am running both in docker containers

This would have been good to have told people at the start

We need to see the startup commands for the two containers to see which ports have been mapped to external ports on the host.

It would be a good idea to install Portainer (you can run that as a container as well) as this will give you much more visibility as to what the containers are doing and let you access their runtime parameters etc

Craig

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 September 2022 02:26 UTC](https://discourse.nodered.org/t/cannot-connect-to-mosquitto-mqtt-broker/64807/12 "2022-09-08T02:26:09Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
