ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

The short answer is that you are not forced to use ROS_HOSTNAME and hostnames but you can also use IP addresses in ROS_MASTER_URI and the ROS_IP variable. If you have a dynamic IP address, you have to change ROS_IP whenever your IP changed and you will have to restart all your nodes.

And here the longer explanation of the why:

There are technical reasons for requiring either a hostname or an ip address.

Let's consider a simple example: computer A runs the core and subscribes to topic with node node_1. Computer B runs node_2 with a publisher for topic.

When the nodes are started up, they first register at the core (the ros::init call does that). To find the master, they use the ROS_MASTER_URI. For negotiating topic connections, each node provides an XMLRPC server. When registering at the master, nodes basically store the URI of this server. For that, the ROS_HOSTNAME and ROS_IP variables are used.

With the advertise call in node_2, it will communicate with the core again to register a publisher for topic.

The subscribe call in node_1 will also communicate with the core to find out which nodes are already publishing topic and the answer will be the address of node_2 that was used when it registered at the core. Note that if the publisher registers after the subscriber, the subscriber node is notified by the core using an XMLRPC call to node_1's local XMLRPC server. Finally, node_1 will directly connect to node_2 and establish the topic connection using the information about node_2's XMLRPC server stored in the core.