Ubuntu Linux for Robotics · Lesson 11 of 96
Networking basics: IP, UDP and multicast
Addresses, ports, TCP vs UDP, multicast groups and why ROS 2 discovery depends on them.
Estimated time · 60–90 min
Learning goals
What you will understand
- Explain networking basics: ip, udp and multicast in your own words
- Use it in a small workstation example
- Verify the result instead of assuming it worked
Understand the idea first
The mental model
An IP address identifies a network interface and a port identifies a service on it. TCP is a reliable connection; UDP sends independent packets with no connection and is faster and lighter. DNS turns names into addresses. Use ip address to see interfaces and ss -lun to see UDP ports that programs are listening on.
Multicast sends one packet to a group of receivers (addresses 224.0.0.0 to 239.255.255.255). ROS 2's DDS uses UDP multicast to discover nodes automatically: if multicast is blocked (a router, a firewall, some Wi-Fi), nodes on different machines do not see each other. Check the interface, the firewall and the ROS_DOMAIN_ID first.
Guided lesson
Work through these steps
- 1.
Open a terminal and record the current state before changing anything.
- 2.
Read the networking basics: ip, udp and multicast commands and predict what each one does.
- 3.
Run the commands one at a time and compare each output with your prediction.
- 4.
Write the commands that worked in a setup note you can repeat later.
Worked example
Read it before you run it
ip -brief address
# Show each interface and its IP address.
ip route
# Show the default route (the gateway).
ss -lun
# List UDP ports that are open for listening.
ping -c 3 192.168.1.1
# Test that the gateway answers (replace with your gateway).
ip maddr show
# List the multicast groups each interface has joined.
sudo tcpdump -i eth0 -n udp port 7400 -c 5
# Capture five DDS discovery packets (7400 is the default RTPS discovery port for domain 0).What the example is doing
- 1.Lines without sudo only inspect or change files you own; sudo authorizes a system-wide change.
- 2.Read command output before moving to the next line. Stop if names, versions, disks, or paths differ from the lesson.
- 3.Comments beginning with # explain safety checks and are not executed by the shell.
Watch it run · Messages between nodes
See what this code does
The terminal types this lesson's practice solution and runs it. The scene shows the kind of robot behaviour that code drives. It plays by itself and loops.
Demo for Networking basics: IP, UDP and multicast. Expected result: A list of UDP sockets that are listening
Practice code
Now type it yourself
Open a terminal, run the starter line by line (or save it as practice.sh and run bash practice.sh), and replace every TODO with your own command.
# TODO: list listening UDP sockets as numbers (ss with the options l, u and n)Expected output
A list of UDP sockets that are listeningStuck? Show the full solution (try it yourself first)
ss -lunExpected result
How you know it worked
- Each command completes without an unexplained error.
- Your notes contain the command, the important output, and what it proves.
Practical exercise
Apply the lesson
Record your interface names and IPs, ping the gateway, run ros2 run demo_nodes_cpp talker on one machine and listener on another, and use tcpdump to see the discovery packets. Then block multicast and observe the failure.
Before you continue
- You recorded the starting state
- Every command and output is understood
- The change can be repeated from your notes
If something goes wrong
Check ownership and permissions first. Do not add sudo unless the command changes a documented system location.
Check spelling, Ubuntu version, enabled repositories, and whether the previous installation command succeeded.