2

I have a MQTT client in an internal network and an MQTT server somewhere in Cloud. How can I connect to MQTT Server without opening port in the Client network?

3

You don't need to open any ports to connect to an external broker on a normal NAT'd internal network (e.g. a normal domestic ADSL setup.).

As long as your network allows all outbound connections (and related replies) then it should all just work.

This is because all MQTT connections are initiated by the client and are then persistent until the client closes the connection. Messages for subscriptions just flow back down this existing connection.

If you need to explicitly allow outbound ports then the default port is 1883.

If you are on a more locked down network, e.g. a corporate network that requires you to use a proxy to reach the outside world then you have 2 choices.

  1. You need an OSI layer 5 proxy e.g. socks
  2. If you only have access to a HTTP proxy then you have to hope that your external broker and client supports MQTT over Websockets.
  • Many thanks. I think I know the point 2 but can you pls elaborate more on point 1? – toto' Jun 22 at 19:03
  • Most totally locked down corporate networks believe that the only protocol that would ever want to leave the network is HTTP/s so deploy HTTP proxies and block anything else. There is an alternative proxy system that can work with ANY protocol, it works at the socket level, the usual implementation is called "socks" (you can run socks over ssh). You need a machine in the DMZ that you can run a standalone socks proxy or you can SSH into – hardillb Jun 22 at 19:52
  • are you saying that if a corporate uses an HTTP proxy to go out, i could ALSO use the socks protocol over such HTTP proxy? Otherwise i do not understand how i can bypass the limitation even with socks. Well maybe unless the corporate agrees to deploy also such socks proxy!? thanks. – toto' Jun 23 at 13:52
  • No, I'm saying you will also need a separate Socks proxy. If you only have a HTTP proxy then your only option is MQTT over Websockets, if you can not add a Socks proxy. – hardillb Jun 23 at 14:24

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.