# Switching between mqtt brokers

**URL:** <https://discourse.nodered.org/t/switching-between-mqtt-brokers/7672>\
**Category:** General\
**Created:** [6 February 2019 21:08 UTC](https://discourse.nodered.org/t/switching-between-mqtt-brokers/7672 "2019-02-06T21:08:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [6 February 2019 21:08 UTC](https://discourse.nodered.org/t/switching-between-mqtt-brokers/7672/1 "2019-02-06T21:08:25Z")

</div>

I'm working (on my laptop) on a project that uses a dozen or more `mqtt` nodes. When I'm at home I want them to connect to a broker on my home LAN, but on the road I want to use a broker on my laptop or a public broker. Is there an easy way to make the switch without having to find and open each `mqtt` node?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 February 2019 21:48 UTC](https://discourse.nodered.org/t/switching-between-mqtt-brokers/7672/2 "2019-02-06T21:48:19Z")

</div>

What OS are you running? If its Linux or OSX, you could edit `/etc/hosts` and add an entry to point `my-broker` at the IP address of the broker and then edit your mqtt nodes to use `my-broker` in place of the ip address. Then when you move between networks you just need to edit `/etc/hosts` with the appropriate IP address.

The alternative option would be to use an environment variable. Configure the broker node to use `$(MY_BROKER)` as the url of the broker. Then ensure that env var is set to the required value when you start node-red.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 February 2019 21:51 UTC](https://discourse.nodered.org/t/switching-between-mqtt-brokers/7672/3 "2019-02-06T21:51:32Z")

</div>

If you use the environment variable route you could have script run on boot that sets it based on what network it can see...

Or you could just have two mqtt input nodes and don't worry about one failing to connect ever 20 secs.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [6 February 2019 22:37 UTC](https://discourse.nodered.org/t/switching-between-mqtt-brokers/7672/4 "2019-02-06T22:37:22Z")

</div>

@knolleary, @dceejay Thanks for the suggestions. I'm running OS X, and the environmental variable idea seems to fit best with my workflow. I'll give it a try.
