Access to my VM by MQTT Port (1883 or 8883)

David M 236 Reputation points
2023-11-02T18:01:09.9333333+00:00

Hello,

I have mount a server mosquitto on my Ubuntu azure VM.
The mosquitto_pub command work in SSH commands, but not with an external acess.

by example: "mosquitto_pub -L "mqtt://mylogin:******@myVm.francecentral.cloudapp.azure.com:1883/sensors/3 ..."

I have add theses ports in allow in firewall azure.

I have an "Error: Connection refused"

WHat i have to do for send on theses ports ?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,033 questions
0 comments No comments
{count} votes

Accepted answer
  1. vipullag-MSFT 26,487 Reputation points Moderator
    2023-11-06T06:27:04.0166667+00:00

    Hello David M

    Welcome to Microsoft Q&A Platform, thanks for posting your query here.

    Based on the details shared, looks likeIt seems that you are trying to connect to the MQTT broker running on your Azure VM from an external device. However, you mentioned that you have already allowed the MQTT ports (1883 and 8883) in the Azure firewall.

    One possible reason for the "Connection refused" error is that the MQTT broker is not listening on the public IP address of your VM. By default, the Mosquitto broker listens on the loopback interface (127.0.0.1) only, which means that it can only accept connections from the same machine.

    To allow external connections to the Mosquitto broker, you need to modify its configuration file (/etc/mosquitto/mosquitto.conf) and add the following lines:

    listener 1883

    listener 8883

    This will make the broker listen on all network interfaces, including the public IP address of your VM.

    After modifying the configuration file, you need to restart the Mosquitto service for the changes to take effect:

    sudo systemctl restart mosquitto

    Once the service is restarted, you should be able to connect to the broker from an external device using the public IP address of your VM.

    Hope this helps.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.