Q&A-23How do ROS 2 nodes find each other and communicate without a central master, and how would you diagnose two nodes that should be talking but never appear in each other's graph?
Answer
ROS 2 has no master. Every node is a DDS participant, and the graph is assembled by the middleware, not a broker. The stack is rclcpp/rclpy → RMW (rmw_fastrtps_cpp by default in Humble/Iron/Jazzy, rmw_cyclonedds_cpp a common swap) → a DDS/RTPS implementation. So "why can't my nodes see each other" is a DDS discovery question, and the first three things I check are domain ID, RMW implementation, and whether multicast actually reaches between the hosts.
| layer | responsibility | what breaks it |
|---|---|---|
| rclcpp / rclpy | nodes, topics, executors, QoS API | — |
| RMW | maps the ROS graph onto DDS entities | RMW_IMPLEMENTATION differs per host |
| DDS / RTPS | SPDP + SEDP discovery, transport | multicast blocked, wrong NIC, domain mismatch |
Discovery runs in two phases. SPDP (Simple Participant Discovery Protocol) has each participant periodically multicast an announcement to 239.255.0.1 on a port derived from the domain ID; Fast DDS defaults are a 20 s lease with an announcement every 3 s. SEDP (Simple Endpoint Discovery Protocol) then exchanges publisher/subscriber, type and QoS details over unicast reliable built-in endpoints. Multicast is only the introduction: matching is unicast.
The port arithmetic is what ROS_DOMAIN_ID actually isolates: Fast DDS uses 7400 + 250 × domainID + offset (offset 10 for multicast discovery, 1 for unicast, 11 for user multicast). Domain 0 → 7400/7410/7411; domain 42 → 17900/17910/17911. Different domain means a different multicast group port and a disjoint participant set, so nodes never discover each other and cannot accidentally share a topic. ROS 2 keeps IDs in 0–101 because above that the derived ports collide with the OS ephemeral range.
Diagnosis splits on one symptom. If the node is missing from ros2 node list, it is the discovery layer: compare ROS_DOMAIN_ID and RMW_IMPLEMENTATION on both sides, then ROS_LOCALHOST_ONLY / ROS_AUTOMATIC_DISCOVERY_RANGE (Iron+; LOCALHOST pins everything to loopback), then multicast reachability. If the node is present but no data flows, discovery succeeded and the problem is QoS or type: ros2 topic info -v prints endpoint QoS, and a RELIABLE publisher will not match a BEST_EFFORT subscriber, nor will a VOLATILE subscriber receive a TRANSIENT_LOCAL publisher's history.
Multicast is the usual culprit. Docker's default bridge network does not forward it, corporate WiFi and VPNs often drop it, and a host with several NICs may announce on the wrong one. Fixes in order of preference: run containers with --network host; set a unicast peer list (Fast DDS XML initialPeersList, CycloneDDS <Peers>, or ROS_STATIC_PEERS for Fast DDS); or run a Fast DDS Discovery Server and point clients at it with ROS_DISCOVERY_SERVER. Peer lists and discovery servers also cut the SPDP chatter that hurts at hundreds of participants.
One trap: ros2 node list goes through the ros2 daemon, which caches the graph. After changing domain or RMW, stop the daemon before believing an empty list.
host A
ROS_DOMAIN_ID=42 ros2 run demo_nodes_cpp talker
host B
ROS_DOMAIN_ID=42 ros2 daemon stop && ros2 node list # expect /talker ROS_DOMAIN_ID=42 ros2 topic info -v /chatter # endpoint count + QoS ROS_DOMAIN_ID=42 ros2 doctor --report # RMW, domain, discovery range
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.