# Mosquitto (on PI) only works in localhost

**URL:** <https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311>\
**Category:** Deployment\
**Created:** [August 26, 2021, 7:11am UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311 "2021-08-26T07:11:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pollux](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@Pollux](https://forum.cedalo.com/u/Pollux)\
**Post date:** [August 26, 2021, 7:11am UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/1 "2021-08-26T07:11:15Z")

</div>

Hello,

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!

 ![2021.08.25 16.330001 PC-POLLUX](https://canada1.discourse-cdn.com/flex030/uploads/streamsheets/original/1X/8887864d6ef66632618c4787ff411295060a0aae.png)  
 ![2021.08.25 16.480002 PC-POLLUX](https://canada1.discourse-cdn.com/flex030/uploads/streamsheets/original/1X/07f88fc89f15551e6ae330dc42ed90eb00cf2da5.png)

---

<div class="post-metadata">

**Author:** ![roger.light](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@roger.light](https://forum.cedalo.com/u/roger.light)\
**Post date:** [August 26, 2021, 9:12am UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/2 "2021-08-26T09:12:20Z")

</div>

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:

```auto
# Completely unauthenticated
listener 1883
allow_anonymous true

```

```auto
# 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/mosquitto_dynamic_security.so
plugin_opt_config_file /var/lib/mosquitto/dynamic-security.json

```

```auto
# 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.

Regards,

Roger

---

<div class="post-metadata">

**Author:** ![Pollux](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@Pollux](https://forum.cedalo.com/u/Pollux)\
**Post date:** [August 26, 2021, 2:03pm UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/3 "2021-08-26T14:03:32Z")

</div>

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

```auto
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 https://mosquitto.org/documentation/authentication-methods/
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.

```auto
allow_anonymous true
listener 1883
protocol mqtt

```

Moreover, the site suggested in the log: “[Authentication methods | Eclipse Mosquitto](https://mosquitto.org/documentation/authentication-methods/)” is clear even to a francophone.  
Good luck and thank you!

---

<div class="post-metadata">

**Author:** ![mboroff](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mboroff](https://forum.cedalo.com/u/mboroff)\
**Post date:** [November 18, 2021, 2:50am UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/4 "2021-11-18T02:50:55Z")

</div>

I could use help with the same problem. I am using V 2.0.1 and Pi Bullseye. My conf file is:

# Place your local configuration in /etc/mosquitto/conf.d/

# 

# A full description of the configuration file is at

# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid\_file /run/mosquitto/mosquitto.pid

persistence true  
persistence\_location /var/lib/mosquitto/

log\_dest file /var/log/mosquitto/mosquitto.log

include\_dir /etc/mosquitto/conf.d

allow\_anonymous true  
listner 1883  
protocol mqtt

---

<div class="post-metadata">

**Author:** ![mboroff](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mboroff](https://forum.cedalo.com/u/mboroff)\
**Post date:** [November 18, 2021, 4:08am UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/5 "2021-11-18T04:08:56Z")

</div>

Additional information. No matter where I place my Mosquitto.conf file the command Mosquitto -v always states it is using a default configuration file. I did try putting the file in /etc/mosquitto/config.d.

---

<div class="post-metadata">

**Author:** ![roger.light](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@roger.light](https://forum.cedalo.com/u/roger.light)\
**Post date:** [November 18, 2021, 3:56pm UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/6 "2021-11-18T15:56:44Z")

</div>

When you run `mosquitto -v` then that won’t load any configuration file. You need to use `mosquitto -c <path to config file>`. The package installation assumes you will be using the built in service management tools for running mosquitto (`sudo systemctl start mosquitto`) which uses the configuration files already. So either try running manually with `-c`, or use systemctl to start or restart the current running instance.

Does that help?

Regards,

Roger

---

<div class="post-metadata">

**Author:** ![mboroff](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@mboroff](https://forum.cedalo.com/u/mboroff)\
**Post date:** [November 18, 2021, 9:36pm UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/7 "2021-11-18T21:36:22Z")

</div>

After editing the conf file I did a systeemctl restart and the log showed it was reading the config changes and not the default. Seems to be working even after a power down restart. Thanks for your help.

---

<div class="post-metadata">

**Author:** ![grant](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@grant](https://forum.cedalo.com/u/grant)\
**Post date:** [November 23, 2021, 1:08pm UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/8 "2021-11-23T13:08:09Z")

</div>

I am having the same issue as @mboroff

Per @roger.light suggestion, when I enter `mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf`

I get the following:

```auto
Loading config file /etc/mosquitto/conf.d/mosquitto.conf
Error: Duplicate pid _file value in configuration
Error found at /etc/mosquitto/conf.d/mosquitto.conf:8
Error found at /etc/mosquitto/conf.d/mosquitto.conf:15

```

[Here are some pics](https://photos.app.goo.gl/hRSE3HFssvLjqrHp9) of my conf file and directory. Am sure I am 98% there.

---

<div class="post-metadata">

**Author:** ![roger.light](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@roger.light](https://forum.cedalo.com/u/roger.light)\
**Post date:** [November 24, 2021, 12:49pm UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/9 "2021-11-24T12:49:23Z")

</div>

Is it possible you have a file in conf.d which is also specifying a pid file?

---

<div class="post-metadata">

**Author:** ![grant](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@grant](https://forum.cedalo.com/u/grant)\
**Post date:** [November 24, 2021, 2:31pm UTC](https://forum.cedalo.com/t/mosquitto-on-pi-only-works-in-localhost/311/10 "2021-11-24T14:31:37Z")

</div>

@roger.light Yes, my .conf file in the conf.d folder had all of the info below:

```auto
pid_file /run/mosquitto/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

allow_anonymous true
listener 1883

```

I removed everything except

```auto
allow_anonymous true
listener 1883

```

and when I start mosquitto using -c /etc/mosquitto/conf.d/mosquitto.conf, it works and all clients on the LAN can reach it. Success!

How I can ensure that upon starting the Raspberry Pi that the correct mosquitto.conf file is used?
