I can't get any data from my broker with mosquitto_sub over the internet - mqtt

in localhost, my broker works great, but when I use broker IP on another device to connect over the internet that's not work,
Websocket is fine
I use this command to subscribe on topic and get the retained messages
mosquitto_sub -h *.*.*.* -p 1883 -t mrt_connections/#
in localhost and when I used VPN I get current information, but when I use broker IP to use with another device over the internet I can't get any data
this log when I used Ip over the internet
1673794013: New connection from ****.****.***.**** on port 1883.
1673794013: New client connected from ****.****.***.**** as auto-48259EF8-9CF7-9CF5-3C2C-20FA8265C33A (p2, c1, k60).
1673794013: No will message specified.
1673794013: Sending CONNACK to auto-48259EF8-9CF7-9CF5-3C2C-20FA8265C33A (0, 0)
1673794017: New connection from *.*.*.* on port 1883.
I guessed that maybe port 1883 is blocked by ISP but another broker with the same port working, I test many IP but the problem is still alive,
can anybody explain to me what is a problem
thanks
I used version 2.0.15
config file
allow_anonymous true
listener 1883 *.*.*.*
log_type all
log_dest topic
log_dest stdout

Finally, I found the problem, the port was blocked by ISP and now MQTT works fine on port 443

Related

Mosquitto MQTT broker not acknowledging external connections (even locally)

I am having some problems with my Mosquitto MQTT broker which I do not understand. I had setup another Mosquitto broker in a Google Cloud Ubuntu 20.04 VM and it was working properly. I have moved to a self-managed Ubuntu 20.04 VM in my university and have not been able to connect to the broker ever since. A little background on the current setup:
netfilter-persistent firewall (am unsure of the exact name of the firewall, this is the name of th service) has port 1883 open
ufw is inactive
the university has 2 levels in the firewall, one in the VM and one external. I have asked for the opening of ports 1883 (I am aware that only port 8883 should be open but this is temporary until I solve my issue)
the VM is accessible from outside the LAN of the university, as checked in https://www.yougetsignal.com/tools/open-ports/
I have an Apache webpage running and it is also accessible externally
I have NodeRED using port 1880 and it is also accessible externally
My Mosquitto conf file looks like the following. For the time being, I am not using TLS authentication, as I first need to solve the issue with the connection.
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883 0.0.0.0
However, I have not been able to enable the communication when using either the server IP or the domain name. If I attempt to connect using localhost, everything works:
~$ mosquitto_sub -h localhost -t test -p 1883 -u "XX" -P "XX" -d
Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending SUBSCRIBE (Mid: 1, Topic: test, QoS: 0, Options: 0x00)
Client (null) received SUBACK
Subscribed (mid: 1): 0
If I attempt to connect with the domain name, I never receive an acknowledgment and the connection is never established:
~$ mosquitto_sub -h domain.com -t test -p 1883 -u "XX" -P "XX" -d
Client (null) sending CONNECT
Client (null) sending CONNECT
Client (null) sending CONNECT
Client (null) sending CONNECT
Client (null) sending CONNECT
Mosquitto seems to be properly bound when running the lsof -i command in the console:
mosquitto 2177304 mosquitto 5u IPv4 10127120 0t0 TCP *:1883 (LISTEN)
mosquitto 2177304 mosquitto 7u IPv4 10127251 0t0 TCP localhost:1883->localhost:47236 (ESTABLISHED)
I would appreciate it if anyone could guide me into what could be the root of my issue. If more information is needed regarding my setup, I will gladly provide it.
Thanks in advance to all!

MQTT Broker does not receive any messages

I'm trying to connect my Tasmota switch over mqtt. i have installed mosquitto on a virtual machine, heres the configuration:
/etc/mosquitto/mosquitto.conf
# 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 /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
/etc/mosquitto/acl
# weewx readwrite to the loop
user tasmota
#topic weather/#
/etc/mosquitto/conf.d/myconfig.conf
allow_anonymous true
password_file /etc/mosquitto/passwd
persistence false
protocol mqtt
acl_file /etc/mosquitto/acl
the service is running, and the port is up
this is the configuration of my switch
im trying to take a look at messages with
mosquitto_sub -h 10.11.0.106 -t '#'
also tried to add user and password, but i dont get any output
i can see in the log, that the connection is established
1579896351: Config loaded from /etc/mosquitto/mosquitto.conf.
1579896351: Opening ipv4 listen socket on port 1883.
1579896351: Opening ipv6 listen socket on port 1883.
1579896351: New connection from 10.10.0.137 on port 1883.
1579896351: New client connected from 10.10.0.137 as mosqsub|19705-warmachin (c1, k60).
1579896358: Socket error on client mosqsub|19705-warmachin, disconnecting.
1579896358: New connection from 10.10.0.137 on port 1883.
1579896358: New client connected from 10.10.0.137 as mosqsub|19775-warmachin (c1, k60).
1579896361: New connection from 10.11.1.51 on port 1883.
1579896361: New client connected from 10.11.1.51 as DVES_6CA231 (c1, k30, u'tasmota').
1579896361: New connection from 10.11.1.52 on port 1883.
1579896361: New client connected from 10.11.1.52 as DVES_301DDC (c1, k30, u'tasmota').
1579896362: New connection from 10.11.1.54 on port 1883.
1579896362: New client connected from 10.11.1.54 as DVES_350992 (c1, k30, u'tasmota').
did i miss something or am i missunderstanding something completely wrong?
please help
As thrashed out in the comments, your ACL file is missing any enabled topics either for the anonymous user or the tasmota user.
If you enable ACLs you need to define all the topics you want users to be able to access.

Mosquitto configuration not accepting listener containing IP address

I have Mosquitto running on a local server, and my aim is to have 3 listeners:
all local network clients to connect without TLS on port 1883 (port 1883 is closed by router to public)
External clients to connect using TLS on port 8883
External client to connect without TLS on port 8880
which using this config works fine;
# Local MQTT
listener 1883
# End Local MQTT
# Insecure MQTT
listener 8880
# End Insecure MQTT
# Secure MQTT
listener 8883
## This is standard and should always be this
cafile /etc/ssl/certs/DST_Root_CA_X3.pem
## These are from your installation of LE
certfile /home/pi/.node-red/certs/fullchain.pem
keyfile /home/pi/.node-red/certs/privkey.pem
## Force all clients in this listener to provide a valid certificate, change th$
require_certificate true
## Stop all unauthorised connections
allow_anonymous false
## Use password file
password_file /etc/mosquitto/passwordfile
and which results in healthy Mosquitto log entries;
1575720819: Opening ipv4 listen socket on port 1883.
1575720819: Opening ipv6 listen socket on port 1883.
1575720819: Opening ipv4 listen socket on port 8883.
1575720819: Opening ipv6 listen socket on port 8883.
1575720819: Opening ipv4 listen socket on port 8880.
1575720819: Opening ipv6 listen socket on port 8880.
1575720820: New connection from 140.238.70.128 on port 8880.
1575719390: New client connected from 140.238.70.128 as telegraf (c1, k60, u'raspPi').
BUT... I want to ensure that only the client at 140.238.70.128 is able to connect on port 8880 (TLS isn't an option) so I added the IP address to the config;
# Insecure MQTT
listener 8880 140.238.70.128
# End Insecure MQTT
but that causes Mosquitto to stop, and the log shows;
1575720699: Opening ipv4 listen socket on port 1883.
1575720699: Opening ipv6 listen socket on port 1883.
1575720699: Opening ipv4 listen socket on port 8883.
1575720699: Opening ipv6 listen socket on port 8883.
1575720699: Opening ipv4 listen socket on port 8880.
1575720699: Error: Cannot assign requested address
I would be grateful for any advice as to why this doesn't work, or an alternative solution.
Edit. I also tried restricting the listener to ipv4, but that gave exactly same result;
# Insecure MQTT
listener 8880 140.238.70.128
socket_domain ipv4
# End Insecure MQTT
The listen directive can only take a address that is local to the machine the broker is running on. This is used to bind a socket to that address on the required port.
You can not use it as a filter for a remote machine, in fact there is no way to configure a port to only accept connections from a specific IP address in mosquitto* (or any other broker that I am aware of).
The only way to achieve what you want to do is to use the machines firewall to drop any packets from other IP addresses addressed to that port. You can use iptables to do this. Something like
iptables -A INPUT -p tcp --dport 8880 ! -s 140.238.70.129 DROP
This should drop any TCP packet destined for port 8880 that is not from 140.238.70.129
While this will work it will only block ipv4 clients, so if your networks has a properly routed IPv6 setup you will need to block access with ip6tables as well (and block access to port 1883).
* you might be able to write a custom auth plugin to do this, but I'm not sure if you get the remote IP address in the details about the user connecting. Also I don't think you can bind authentication to just one listener.

mqtt broker bridge (in windows machine)

I'm working in mqtt broker bridge, I have to connect local mosquitto to remote mosquitto.
connection remote-mosquitto-bridge
address 10.1.0.9:1883
topic test both 1
Above code is added in mosquitto.conf file for connect remote machine(10.1.0.9 is my remote)
its enough for message sharing to local to remote
You need config the listener port
ex:
if your diagram is like that
broker 1 => broker 2
Broker 1 mosquitto.config:
connection remote-mosquitto-bridge
address 10.1.0.9:1883
topic # both 0
Broker 2 mosquitto.config:
port 1883
listener 8883
This work for me.
source:
https://medium.com/jungletronics/mosquitto-bridge-5b44e9687fb3

Mosquitto - EMQX bridge connection name

1) How to determine the Mosquitto bridge connection name.
The snippet written below is from the EMQx documentation (http://emqtt.io/docs/v2/bridge.html#mosquitto-conf)
connection emqttd
address 127.0.0.1:2883
topic sensor/# out 2
the connection name - emqttd is written on what basis?
2) I have a tcp connection open from EMQX on the host 172.22.25.53 and port 2883.
When i try connecting from the same system. It works absolutely fine. But from a different system, I get this error
C:\Program Files\mosquitto>mosquitto.exe -c mosquitto.conf -v
1542182003: mosquitto version 1.5.3 starting
1542182003: Config loaded from mosquitto.conf.
1542182003: Opening ipv6 listen socket on port 1883.
1542182003: Opening ipv4 listen socket on port 1883.
1542182003: Bridge local.AOI146.emq#172.22.25.53 doing local SUBSCRIBE on topic BA/#
1542182003: Connecting bridge emq#172.22.25.53 (172.22.25.53:2883)
1542182003: Bridge AOI146.emq#172.22.25.53 sending CONNECT
1542182003: Error creating bridge: Unknown error.
1542182003: Warning: Unable to connect to bridge emq#172.22.25.53.
My mosquitto.conf file is:
connection emqx
address 172.22.25.53:2883
cleansession false
topic AB/# both 2
The connection name is the value after connection in the configuration file. As described in the bridge section of the mosquitto.conf man page
e.g.
connection foo
Will result in a connection name of foo.
172.22.25.53 is in the reserved range 172.16.0.0 – 172.31.255.255, I'm going to guess you are running emq in a docker container and you are trying to access the container using it's Docker internal IP address. You will need to expose the port on your host machine to be able to access it from a remote machine.

Resources