Mosquitto not accepting connections

Hello,

I've installed mosquitto-ssl and libmosquitto-ssl packages.

everything is placed in /etc/mosquitto

had to change permissions in order to be able to run mosquitto without file access errors

root@fire:/etc/mosquitto# ls -la
drwxr-xr-x    2 root     root          3488 Jun 22 12:38 .
drwxr-xr-x    1 root     root          3488 Feb  5 00:36 ..
-rwxrwxrwx    1 root     root           391 Jun 22 12:24 mosquitto.conf
-rw-------    1 root     root         40449 Feb  5 00:36 mosquitto.conf-opkg
-rwx------    1 mosquitt mosquitt         0 Jun 22 12:38 mosquitto.db
-rwx------    1 mosquitt mosquitt     21427 Jun 22 12:41 mosquitto.log
-rwx------    1 mosquitt mosquitt       122 Jun 22 12:31 passwords.txt

created 3 firewall rules

config rule
        option name 'mqtt'
        list proto 'tcp'
        option src_port ' 1883 9001'
        option dest_port ' 1883 9001'
        option target 'ACCEPT'
        list dest_ip '192.168.10.1'
        option src '*'

config redirect
        option target 'DNAT'
        option name 'mqtt 1883'
        list proto 'tcp'
        option src 'iot'
        option src_dport '1883'
        option dest_port '1883'
        option dest_ip '192.168.10.1'

config redirect
        option target 'DNAT'
        option name 'mqtt 9001'
        list proto 'tcp'
        option src 'iot'
        option src_dport '9001'
        option dest_port '9001'
        option dest_ip '192.168.10.1'

mosquitto.conf

# Global
# Must be set before configuring listeners
per_listener_settings true

# Default listener
listener 1883
listener 9001

# Security
allow_anonymous false
password_file /etc/mosquitto/passwords.txt

persistence true
persistence_file mosquitto.db
persistence_location /etc/mosquitto/
autosave_interval 1800

log_timestamp true
log_dest file /etc/mosquitto/mosquitto.log
log_dest stdout

running mosquitto -v -c /etc/mosquitto/mosquitto.conf gives the following output

root@fire:/etc/mosquitto# mosquitto -v -c /etc/mosquitto/mosquitto.conf
1719057164: Warning: Persistence file is empty.
1719057164: mosquitto version 2.0.18 starting
1719057164: Config loaded from /etc/mosquitto/mosquitto.conf.
1719057164: Opening ipv4 listen socket on port 1883.
1719057164: Opening ipv6 listen socket on port 1883.
1719057164: Opening ipv4 listen socket on port 9001.
1719057164: Opening ipv6 listen socket on port 9001.
1719057164: mosquitto version 2.0.18 running
1719057164: New connection from 192.168.11.142:6041 on port 1883.
1719057164: Sending CONNACK to shellyswitch (0, 5)
1719057164: Client shellyswitch disconnected, not authorised.

terminating the service i get the following

^X^C1719057274: mosquitto version 2.0.18 terminating
1719057274: Saving in-memory database to /etc/mosquitto//mosquitto.db.
1719057274: Error saving in-memory database, unable to open /etc/mosquitto//mosquitto.db.new for writing.
1719057274: Error: Permission denied.

What can i do to solve this issue?

Thanks in advance

If the service is running on the router, and it is servicing your LAN, then you do not need any of the rules.

1 Like

"/etc" is a bad place to put frequently-written files, you will destroy your flash memory rapidly. In general, you can place the database under "/var", so it stays on RAM.

2 Likes

Unnecessary trailing slash ?

Temporary set to true and retest.

Worth checking passwords, etc. ?

Killed all mosquitoes in the system..

uninstalled all mosquito files
removed any leftovers
deleted firewall rules
reboot
installed mosquitto-ssl mosquitto-client-ssl libmosquitto-ssl
created a new /etc/mosquitto/mosquitto.conf

  GNU nano 8.0                                               mosquitto.conf                                                         # Global
# Must be set before configuring listeners
per_listener_settings true

# Default listener
listener 1883
listener 9001

# Security
allow_anonymous true
#password_file /etc/mosquitto/passwords.txt

persistence true
persistence_file mosquitto.db
persistence_location /var/mosquitto/
autosave_interval 1800

log_timestamp true
log_dest file /etc/mosquitto/mosquitto.log
log_dest stdout

tested with no passwd

root@fire:/etc/mosquitto# mosquitto -v -c /etc/mosquitto/mosquitto.conf
1719073956: Error: Unable to open log file /etc/mosquitto/mosquitto.log for writing.

^X^C1719073968: Error: No such file or directory.
root@fire:/etc/mosquitto# ls
mosquitto.conf      mosquitto.conf.old
root@fire:/etc/mosquitto# chmod 0777 /etc/mosquitto
root@fire:/etc/mosquitto# mosquitto -v -c /etc/mosquitto/mosquitto.conf
1719073982: mosquitto version 2.0.18 starting
1719073982: Config loaded from /etc/mosquitto/mosquitto.conf.
1719073982: Opening ipv4 listen socket on port 1883.
1719073982: Opening ipv6 listen socket on port 1883.
1719073982: Opening ipv4 listen socket on port 9001.
1719073982: Opening ipv6 listen socket on port 9001.
1719073982: mosquitto version 2.0.18 running
1719073991: New connection from 192.168.10.5:48938 on port 9001.
1719073991: Client <unknown> disconnected due to protocol error.
1719074000: New connection from 192.168.10.5:48947 on port 1883.
1719074000: Sending CONNACK to mqtt-explorer-fbcad2d2 (0, 5)
1719074000: Client mqtt-explorer-fbcad2d2 disconnected, not authorised.
1719074008: New connection from 192.168.10.5:48951 on port 1883.
1719074008: Sending CONNACK to mqtt-explorer-fbcad2d2 (0, 5)
1719074008: Client mqtt-explorer-fbcad2d2 disconnected, not authorised.
^X^C1719074013: mosquitto version 2.0.18 terminating
1719074013: Saving in-memory database to /var/mosquitto//mosquitto.db.
1719074013: Error saving in-memory database, unable to open /var/mosquitto//mosquitto.db.new for writing.
1719074013: Error: No such file or directory.

before running

root@fire:/etc/mosquitto# ls -la
drwxr-xr-x    2 root     root          3488 Jun 22 17:31 .
drwxr-xr-x    1 root     root          3488 Jun 22 17:28 ..
-rw-r--r--    1 root     root           391 Jun 22 17:31 mosquitto.conf
-rw-------    1 root     root         40449 Feb  5 00:36 mosquitto.conf.old

after

root@fire:/etc/mosquitto# ls -la
drwxrwxrwx    2 root     root          3488 Jun 22 17:33 .
drwxr-xr-x    1 root     root          3488 Jun 22 17:28 ..
-rw-r--r--    1 root     root           391 Jun 22 17:31 mosquitto.conf
-rw-------    1 root     root         40449 Feb  5 00:36 mosquitto.conf.old
-rw-------    1 mosquitt mosquitt      1163 Jun 22 17:33 mosquitto.log

Maybe a permission problem?

but you have no settings for listener 1883 that you use in the test

That was half os the problem, but thanks for helping.

The other half had to do with file permissions.

Thanks again.

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