New router, broker IP question

Here's the problem. I installed Mosquitto on a Raspberry Pi a bit more then two years ago. The router DHCP assigned 192.168.1.124 to the Pi, and I marked it as a permanent lease in the router.

Now, I am planning a migration to a new router.

How can I make the new router's DHCP assign the same IP? The alternative is manually setting the new broker IP on each node. Fortunately most are running Tasmota, but some are coded in Arduino (using the PubSub library) and the broker IP is hard-coded.

So, what would you do?

You might have to set the IP range on the router to use 192.168.1.x (depends on the router, some use 192.168.0.x) & you could reserve it again on the new router, but ultimately I would recommend setting the IP as static.

"How to give your Raspberry Pi a Static IP Address - UPDATE– The Pi Hut" How to give your Raspberry Pi a Static IP Address - UPDATE– The Pi Hut

I know I could give the Pi a static IP and start the DHCP range after the IP of the Pi, but that only leaves me with 130 DHCP addresses. Sounds like a lot but I already use 60 DHCP addresses and would feel like being painted into a corner.

I am thinking of setting up a second broker and using node-red to bridge them. This way I could change the broker IP address in the devices at my leisure.

Before doing anything dramatic, see if your new router does a cashing DNS server where the local hosts doing DHCP get their hostnames assigned in the DNS and remote host names get forwarded to your ISP DNS server.

Then change your fixed IP address to use hostname or hostname.local.

Once you've used a router with this feature you'll never be satisfied with one that lacks it again.

Unfortanately few IP cameras have a proper hostname or implement the DHCP and/or AHAVI protocols correctly so when you change routers you'll have to lock the MAC address to the IP the camera uses.

To minimize the hassle, first off change your router to make the 198.168.xxx.yyy
match what you are using now, where xxx (usually 0,1or2) is the subnet and yyy is the router default address (usually 1, but my U-Verse router uses 254 and can't be changed as far as I can tell). Normally this doesn't matter as its what DHCP sets as the "default gateway".

If I boot a fresh Pi or Beaglebone on my router I can find its IP by doing ping pi.local or ping beaglebone.local Once I've given them a unique hostname I hever have to worry about what the actual IP address is.

If you've read through the above, my simple suggestion is to make sure the new router is 192.168.1.yyy I've never seen one that can't be changed unless provided by your ISP.

Then lock the MAC address of the Mosquitto broker Pi to 192.168.1.124

You can extend the DHCP range in the router.

For the basic question why don't you just do what you did with the original router, tell the router to always give the Pi the right ip address as a permanent lease?

1 Like

Yes, I can assign a permanent lease to the pi in the new router, but the problem is in the dozens of devices I have with the broker IP address of 192.168.1.124 hard coded. There's nothing to tell the new router DHCP to assign 192.168.1.124 to the pi.

(I wonder, could I use a hostname in pubsub setServer() instead of a hard-coded IP? This would make the reflashing of everything a last-time event.)

Tell the router to assign 192.168.1.124 to the pi.

Are you sure? Most routers enable address reservation in the LAN settings.
I also have a number of devices with the broker IP hard coded, and have changed my router twice in the last year (for better models!), and have just reserved the original IP for my Pi.

What router do you have? have you looked through the available router admin settings.

1 Like

Thanks for the tip. I finally found it, but it is well hidden deep, deep in the router's menus. And it's not called anything like "address reservation".

But, I just tried it on an Arduino and it works.

To give you an idea of how big a task reflashing would be, here is an image of my DHCP distribution page on the router. They aren't all IOT devices, but about half are.

Normally, only the broker (your Pi) needs a fixed IP address, and the clients (IoT devices) can use whatever IP addresses that the DHCP server (Router) assigns them.
MQTT brokers don't need to know the IP addresses of it's clients.
(I wasn't sure if you were already aware of that)

Most of my devices are running Tasmota, and Tasmota needs to know the address of the broker.

But that is all moot now. Thanks to the tip from Paul-Reed, I can now force the broker to be on the same IP on the new router.

Besides that, I also determined that Tasmota works just fine with the brokers hostname instead of the IP address. So as I casually (no rush now) flash new versions of Tasmota on them, I will use the hostname of the broker instead of the IP address.

1 Like

That isn't a Tasmota issue, that is a question of whether your network propagates local hostnames reliably. I have had issues with that in the past working mostly but occasionally it would fail so I have reverted to using IP addresses in low level devices. In PCs and Pis I populate /etc/hosts with host names and IP addresses so I can use host names there.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.