I have three VMs (VirtualBox, Ubuntu 18.04). All of them with Mosquitto broker (configured as default localhost:1883). Two VMs are PUB with private IPs and a "server" is a SUB (assigned via DHCP -bridged-). What I have is:
VM1 (PUB) [192.168.1.66]
VM (SUB) [192.168.1.55]
VM2 (PUB) [192.168.1.74]
The idea is the SUB to receive MQTT from all PUBs, however, it only works if the MQTT client is configured as following
VM1 [192.168.1.66:1883] --> VM [192.168.1.66:1883] <-- VM2 [192.168.1.74:1883]
So, the SUB will only receive messages from VM1 but not from VM2 neither other VMs (PUB). How can I configure the mosquitto and the client at the SUB to receive messages from all PUBs?
A MQTT client instance can only connect to a single MQTT Broker.
You have 2 options.
Run just one broker on any of the 3 machines and have all the publishing clients just publish to that broker and likewise the subscriber .
You can configure one of the brokers to bridge to all the other brokers and subscribe to any messages published on those broker so they they will appear in the topic hierarchy of that single broker.
Details of how to configure mosquitto bridges can be found in the man page here