skip to Main Content

PROBLEM

I have installed ROS 2 foxy on 2 computers and trying to run the demo talker on one machine and the demo listener on the other. Unfortunately it does not work.

However:

  • the ros2 multicast test works;
  • the talker/listener DO work when I completely disable the firewall.

I would like to know how to configure the firewall (or any other system parameter) so the talker/listener will work without having to completely disable the firewall.

Note that ros2 is installed on the OS directly, not in Docker.

COMPUTERS

Both computers:

  • are on the same network (home network with simple router);
  • are connected by cables to the router;
  • have static IPs;
  • run Ubuntu 20.04.5 LTS (focal).
$ lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:    20.04
Codename:   focal

FIREWALL: UDP MULTICAST ENABLED

I have configured ufw to allow UDP multicast on both machines as per ref. [1] below.

$ sudo ufw allow in proto udp to 224.0.0.0/4
Rule added
$ sudo ufw allow in proto udp from 224.0.0.0/4
Rule added
$ sudo ufw status numbered
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 22/tcp                     ALLOW IN    Anywhere                  
[ 2] 224.0.0.0/4/udp            ALLOW IN    Anywhere                  
[ 3] Anywhere                   ALLOW IN    224.0.0.0/4/udp           
[ 4] 22/tcp (v6)                ALLOW IN    Anywhere (v6)  

Following this configuration, I am able to run the ros2 multicast test between both machines.

machine1 $ ros2 multicast send
Sending one UDP multicast datagram...

machine2 $ ros2 multicast receive
Waiting for UDP multicast datagram...
Received from 192.168.1.108:34434: 'Hello World!'

However, the talker/listener do not hear each other.

machine1 $ ros2 run demo_nodes_cpp talker
[INFO] [1672838648.074547042] [talker]: Publishing: 'Hello World: 1'
[INFO] [1672838649.074330969] [talker]: Publishing: 'Hello World: 2'

machine2 $ ros2 run demo_nodes_cpp listener
(waits forever...)

FIREWALL: DISABLED

By disabling the firewall on both machines, the talker/listener can hear each other.

machine1 $ sudo ufw disable
Firewall stopped and disabled on system startup
machine1 $ ros2 run demo_nodes_cpp listener
[INFO] [1672838846.953415499] [listener]: I heard: [Hello World: 1]
[INFO] [1672838847.953088937] [listener]: I heard: [Hello World: 2]

machine2 $ sudo ufw disable
Firewall stopped and disabled on system startup
machine2 $ ros2 run demo_nodes_cpp talker
[INFO] [1672838846.944245747] [talker]: Publishing: 'Hello World: 1'
[INFO] [1672838847.944211861] [talker]: Publishing: 'Hello World: 2'

QUESTION

How could I configure my firewall (or any other OS parameter) so the talker/listener can see each other without having to disable the firewall?

REFERENCES

[1] https://docs.ros.org/en/foxy/How-To-Guides/Installation-Troubleshooting.html

3

Answers


  1. Chosen as BEST ANSWER

    SOLUTION

    All right so the issue was that my firewall was blocking communications between my computers... The issue was solved simply by allowing UDP in on both machines.

    Machine 1 $ sudo ufw allow in proto udp from 192.168.1.0/24
    Machine 2 $ sudo ufw allow in proto udp from 192.168.1.0/24
    

    A good practice might be to specify the exact IP of each machine & the exact source/destination ports on each machine, but since these are 2 computers I only use from time to time the rules specified above were OK for me...

    NOTE REGARDING ros2 multicast

    One thing that still bugs me is that, when running on the same machine, ros2 run demo_nodes_cpp works correctly while ros2 multicast does not (ros2 multicast requires to sudo ufw allow in proto udp to/from 224.0.0.0/4 as mentionned here).

    By following ignacio's advice and using wireshark, I observed that ros2 run demo_nodes_cpp actually broadcasts to address 239.255.0.1, while ros2 multicast broadcasts to 224.0.0.0.

    I find it odd that ros2 multicast broadcasts to a different address than ros2 run, as the goal of ros2 multicast is to validate ros2 run can send data... This seems to be an incoherence with ROS2. Maybe ros2 multicast was developped for an earlier version of ROS2 (before foxy) and is no longer relevant for newer versions? I don't know... And I must admit my knowledge of multicasting is limited.

    So for now, I am simply assuming ros2 multicast is a tool which should not be used and that the following command must be ran when running ROS2 systems on several machines on the same network.

    $ sudo ufw allow in proto udp from 192.168.1.0/24
    

  2. I think it depends which DDS Implementation you are going to use as middleware. foxy uses eProsima by default. Their manual eprosima-fast-rtps.pdf might have the ports that you are looking for.

    Maybe you could also use wireshark instead to check which ports are used and enable those.

    Login or Signup to reply.
  3. I found ROS_LOCALHOST_ONLY was set to 1 on my server. It had not been changed since installation (following ROS2 first tutorials it is mentioned and usually added to bash along with ROS_DOMAIN_ID). So the solution for me was to unset ROS_LOCALHOST_ONLY.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search