ROS_DOMAIN_ID

The default middleware that ROS 2 uses for communication is DDS. In DDS, the primary mechanism for having different logical networks share a physical network is known as the Domain ID. ROS 2 nodes on the same domain can freely discover and send messages to each other, while ROS 2 nodes on different domains cannot. All ROS 2 nodes use domain ID 0 by default.

  • Make sure both machines have the same ROS_DOMAIN_ID
echo $ROS_DOMAIN_ID
0

Run ROS2 on 2 machines

ros2 run demo_nodes_cpp talker
[INFO] [1735955684.018815006] [talker]: Publishing: 'Hello World: 1'
[INFO] [1735955685.018882451] [talker]: Publishing: 'Hello World: 2'
[INFO] [1735955686.018849702] [talker]: Publishing: 'Hello World: 3'
[INFO] [1735955687.018847096] [talker]: Publishing: 'Hello World: 4'
# Open new terminal
ros2 run demo_nodes_cpp listener