4

I have linux server running with public ip. I have set up mosquitto broker with the following commands.

apt-get install mosquitto
apt-get install libmosquitto-dev
apt-get install mosquitto-clients

My broker is running in linux server.I am listening on port 1883. It is working fine when I try to run this in the server with the following commands.

mosquitto_sub -h localhost -t "mqtt" -v
mosquitto_pub -h localhost -t "mqtt" -m "Testing"

But it is not working from outside when I try to access this broker from home network. I am trying MQTTlens as a tool to test the broker.

  • 2
    When you say from outside, do you mean from a different machine on the same network or a remote machine on a different network? Also how are you configuring MQTTlens? Finally have you checked if port 1883 is open in iptables? – hardillb Oct 2 '17 at 10:38
  • 1
    a remote machine from different network. In mqttlens I am giving server ip address and port. After that I am trying to listen under a topic. – Abdul Alim Shakir Oct 2 '17 at 10:43
  • 2
    OK, edit the question to add a lot more details. We need to know what sort of network this is (e.g. is broker running on a machine attached to a home network, is it somewhere like AWS) – hardillb Oct 2 '17 at 10:46
  • 2
    There is no term "Real IP", Public IP or Private IP (RFC1918). Please clarify your answer. – MatsK Oct 2 '17 at 15:26
  • 2
    Please add relevant logs from mosquitto and perhaps the firewall. – MatsK Oct 3 '17 at 15:21
2

If I am not wrong in understanding you question, You are trying to connect to the broker via a device which is not on the same network as the broker is.

If that's the case then the thing is that MQTT broker is present only in your private network and it's not public even if you know the public IP as the public IP address is handled by NAT on your router.

To make your broker public, you need to forward the port 1883 in your router so that any requests on that port be forwarded to the device that is running your broker. You can check online on how to port forward on your specific router model.

Tl;dr forward the port you are listening on your router and then use public ip to connect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.