Stage 03 · Lesson 12/14

Linux & Dev Environment · Lesson 12

Networking Fundamentals

Est. 40–50 min

Why

Why your laptop and robot must find each other

Remote control, SSH, ROS 2 topics between laptop and robot, camera streams — all of it rides on this. When “it does not connect”, the cause is almost always one of: wrong address, different network, wrong port, or a firewall.

Concept

The big idea: IP address = flat number, port = which person inside

Networking words in society language
WordSociety analogyExample
IP addressFlat number192.168.1.42
Subnet (/24)Same society — first three numbers match192.168.1.0/24 = 192.168.1.1 … 192.168.1.254
Router / gatewayMain gateOften 192.168.1.1
PortIntercom extension inside the flat22 (SSH), 80/443 (web), 5005 (your app)
localhost / 127.0.0.1Talking to someone in your own flatTest a server on the same machine
Hostname / DNSName on the society directoryjetson.local → 192.168.1.42
DHCPSociety office assigning flat numbersRouter gives the robot an IP when it joins
  • Private ranges (used inside homes, labs, colleges): 10.x.x.x, 172.16–31.x.x, 192.168.x.x. They are not reachable directly from the internet.
  • Same subnet means devices can talk directly. 192.168.1.10 and 192.168.0.42 are in different societies — they need a router between them.
  • DHCP addresses can change. For a robot, ask the router for a reserved (fixed) address or use the hostname.
Commands to diagnose
CommandAnswers the question
ip -brief addr (or hostname -I)What is MY IP address?
ip routeWhere is my main gate (default gateway)?
ping -c 3 192.168.1.42Can I reach the robot at all?
ss -tlnWhich ports is THIS machine listening on?
ping -c 3 jetson.localDoes the name resolve? (mDNS, often works on Ubuntu/Jetson)

How it works

How it actually works: a message from laptop to robot

  1. Your app opens a connection

    Python asks the OS: connect to 192.168.1.42, port 5005.

  2. Same society?

    The OS compares the address with its own subnet (192.168.1.0/24). Same → send directly over Wi-Fi/Ethernet. Different → hand it to the gateway.

  3. Delivery

    The robot’s network card receives the packet; its OS checks which program is listening on port 5005.

  4. Answer

    That program replies to your laptop’s address and a temporary port your OS picked. You now have a two-way conversation (TCP).

  5. No listener?

    “Connection refused” = robot reachable, but nothing on that port. “Timed out” = packet never arrived (wrong IP, other network, firewall).

Visual

Visualise it: laptop ↔ robot on one LAN

A simulated LAN with your laptop and a Jetson at 192.168.1.42. Try hostname and whoami on each side and see which machine answers.

Interactive · Robot network & SSH

Laptop192.168.1.10LAN / Wi-FiJetson192.168.1.42
# robot network lab — simulated LAN only
# laptop (dev) ↔ Jetson (on-robot computer)
# try: ssh robot@192.168.1.42

Worked example

Worked example: “I can’t reach the robot”

StepCommand / checkKavya finds
1ip -brief addr on the laptopwlan0 192.168.0.15/24
2Robot’s IP (from its screen or router page)192.168.1.42
3Compare the first three numbers192.168.0 vs 192.168.1 — different networks!
4Laptop was on the guest Wi-FiSwitch to the lab Wi-Fi
5ping -c 3 192.168.1.42Replies come back — now SSH will work
NoteCollege and office Wi-Fi often isolate clients so devices cannot see each other. A small dedicated router for the robot lab avoids this.

Code lab

Code lab: same network? and a tiny PING/PONG

Python’s built-in ipaddress module answers the “same society?” question, and socket lets two programs talk over a port. Here both “laptop” and “robot” run on your own machine through 127.0.0.1, so it works anywhere — no robot needed.

net_basics.py · Python
# net_basics.py — same network? and a tiny PING/PONG over a TCP port (Lesson 12)
import ipaddress
import socket
import threading

lan = ipaddress.ip_network("192.168.1.0/24")
for host in ["192.168.1.10", "192.168.1.42", "192.168.0.42"]:
    print(f"{host:13} in {lan}? {ipaddress.ip_address(host) in lan}")

# A mini "robot" server on this same computer (127.0.0.1 = localhost), port 5005
srv = socket.socket()
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(("127.0.0.1", 5005))
srv.listen(1)

def robot():
    conn, _ = srv.accept()
    with conn:
        if conn.recv(16) == b"PING":
            conn.sendall(b"PONG from robot")

threading.Thread(target=robot, daemon=True).start()
with socket.create_connection(("127.0.0.1", 5005), timeout=2) as laptop:
    laptop.sendall(b"PING")
    print("laptop got:", laptop.recv(32).decode())
srv.close()

Expected output

192.168.1.10  in 192.168.1.0/24? True
192.168.1.42  in 192.168.1.0/24? True
192.168.0.42  in 192.168.1.0/24? False
laptop got: PONG from robot

Real world

Where networking shows up in robotics

  • Laptop and Jetson on the same router: SSH, file sync and ROS 2 traffic all work directly.
  • A web dashboard on the robot at http://192.168.1.42:8080 (IP + port).
  • ROS 2 discovery uses the local network; robots on the same network with the same ROS_DOMAIN_ID see each other.
  • Camera streams use a lot of bandwidth — Ethernet is more reliable than crowded Wi-Fi for demos.

Mistakes

Common mistakes and debugging

Hardware & safety

Hardware lab and safety notes

Your laptop and the robot computer must be on the same network before anything else works.

  • Put the laptop and Pi/Jetson on the same Wi-Fi router (or one Ethernet switch).
  • Find the robot’s IP with hostname -I on the robot, or in the router’s client list.
  • College and office Wi-Fi often block device-to-device traffic (“client isolation”); a small dedicated router or phone hotspot avoids this.
Raspberry Pi 4 Model B single-board computer, top view
A Raspberry Pi on the lab Wi-Fi — note its IP with hostname -I.Photo: Laserlicht · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP

Debugging

Debugging: when it doesn’t work

Symptom → likely cause → fix
SymptomLikely causeFix
ping times outDifferent subnets or client isolationCompare ip a on both; use the same router
Connection refusedRight machine, nothing listening on that portStart the server; check the port number
Name or service not known.local name not resolvingUse the IP address; install avahi on the robot
Worked yesterday, not todayRouter gave a new IP (DHCP)Check hostname -I again or reserve the IP in the router
NoteRead the last line of an error first — it usually names the problem. Change one thing at a time and re-run.

Think

Think about it

Think

Your laptop is 192.168.1.10/24 and the robot is 192.168.0.42/24. Can they talk directly?

Experiment

Try it in the lab: find and reach the robot

Use the simulated LAN, then try the real commands on your laptop.

Experiment

Find and reach the robot

You will need

  • Robot network simulator
  • Optional: laptop + Raspberry Pi / Jetson on the same Wi-Fi

Steps

  1. In the simulator, run `hostname` and `whoami` on the laptop side.
  2. Connect with `ssh robot@192.168.1.42`, run `hostname` again. What changed?
  3. Type `exit` and confirm you are back on the laptop.
  4. On your real laptop run `ip -brief addr` and `ip route`. Write your IP and gateway.
  5. Run `net_basics.py`. Then change one host to `10.0.0.5` and predict the result before running.

Interactive · Robot network & SSH

Laptop192.168.1.10LAN / Wi-FiJetson192.168.1.42
# robot network lab — simulated LAN only
# laptop (dev) ↔ Jetson (on-robot computer)
# try: ssh robot@192.168.1.42

The prompt and hostname tell you which machine you are on. Mixing up terminals is the most common networking “bug” of all.

Knowledge check

Check your understanding

Knowledge check

1. An IP address on a LAN is like…

2. A port number identifies…

3. 127.0.0.1 always means…

4. “Connection refused” most likely means…

5. Which of these is a private (LAN) address?

Mini assignment

Hands-on assignment

Mini assignment

Lab network sketch

Draw and document your robot lab network.

Deliverables

  • Sketch: router, laptop, robot computer, with IPs, subnet and gateway
  • Which ports each machine uses and for what (at least SSH)
  • A 5-step “can’t connect” checklist in your own words
  • Output of net_basics.py with one host you changed

Do this, step by step

  1. In the network lab, ping the Jetson and SSH into it; run hostname on each side.
  2. Run net_basics.py, then change one host to 10.0.0.5 and predict the result first.
  3. Run ip a on your laptop and write your IP, subnet and gateway.
  4. Draw the lab network sketch and your 5-step “can’t connect” checklist.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Hint 1: In ip a, look for inet 192.168.x.y/24 under wlan0 or eth0.
  2. Hint 2: /24 means the first three numbers must match to be on the same subnet.
  3. Hint 3: Checklist order: same network? → ping → right IP? → port open? → firewall?

Challenges (pick by level)

  • 🟢 Easy: ping -c 3 your router (gateway) and note the time in ms.
  • 🟡 Medium: Use Python ipaddress to check if two IPs are in the same /24.
  • 🟠 Hard: Run a tiny TCP echo server on one machine and connect from the other.

Next step

Look back: Lesson 11: Python Virtual Environments. Next: Lesson 13: SSH & Remote Robotics Development. Related: Stage 10 — ROS 2 (ROS 2 nodes on different machines talk over this network).

Sources

Self-attested for now — keep artifacts in your lab notebook.

Complete

Today's goal

0 of 1 done today

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in