Link: http://wiki.ros.org/multimaster_fkie

apt install ros-melodic-master-discovery-fkie  ros-melodic-master-sync-fkie

On each machine, run:

rosrun master_discovery_fkie master_discovery& rosrun master_sync_fkie master_sync

Each one of the ROS hosts involved should know each other ROS host by name. This can be accomplished either by a dedicated DNS server in the network, e.g., dnsmasq or by adding the appropriate DNS entries in each machine's /etc/hosts file. If we're working with two computers, named AAA and BBB, then:

To verify that the above works, you should be able to ping each machine from each other machine by their hostname.

After that's in place, you can verify that you can see all the topics and nodes active in AAA by running rostopic list or rosnode list from a shell in BBB.