# Dynamic host for MQTT

**URL:** <https://discourse.nodered.org/t/dynamic-host-for-mqtt/14257>\
**Category:** General\
**Created:** [12 August 2019 17:57 UTC](https://discourse.nodered.org/t/dynamic-host-for-mqtt/14257 "2019-08-12T17:57:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![doubleg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/doubleg/32/10923_2.png) [@doubleg](https://discourse.nodered.org/u/doubleg)\
**Post date:** [12 August 2019 17:57 UTC](https://discourse.nodered.org/t/dynamic-host-for-mqtt/14257/1 "2019-08-12T17:57:42Z")

</div>

Hi everyone ! 🙂

Is there a way to change de MQTT host / IP during runtime like the TCP node with msg.host and msg.port?

I need to be able to communication with a lot of node-red instances on different locations using MQTT and I don't want to hardcode all the different IP since all these IP are available in my SQL Database.

Thank you very much !

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 August 2019 18:21 UTC](https://discourse.nodered.org/t/dynamic-host-for-mqtt/14257/2 "2019-08-12T18:21:30Z")

</div>

so have one broker and use a bunch of different topics

pi1 pub/sub's using topic: pi1/something  
pi2 pub/sub's using topic: pi2/something

the can both use the same broker

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 August 2019 17:41 UTC](https://discourse.nodered.org/t/dynamic-host-for-mqtt/14257/3 "2019-08-13T17:41:02Z")

</div>

Perhaps you don't quite understand the role of MQTT?

As @zenofmud said, use topics. This way, all of your node-red installations can intercommunicate and IP is irrelevant.

You could even build a topic from the DB like `data/ip/name`

Then you can subscribe to all messages from 1 IP...  
`data/ip/#`

Or subscribe to all certain values for all IPs  
`data/#/size`

---

<div class="post-metadata">

**Author:** ![doubleg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/doubleg/32/10923_2.png) [@doubleg](https://discourse.nodered.org/u/doubleg)\
**Post date:** [13 August 2019 18:03 UTC](https://discourse.nodered.org/t/dynamic-host-for-mqtt/14257/4 "2019-08-13T18:03:14Z")

</div>

Thank you very much for the replies guys, I will use a centralized broker for the communication between all the node-red instances it will certainly do the job. Have a nice day !
