Sign inSign up free

1034. Which Route Does a Packet Take?

hard 40 XP ~14 minHands-on lab

Support tickets come with a saved ip route output, and people answer "which way does traffic to X go?" by eye, often wrongly. /home/student/routes.txt is an example.

Task

Create the executable script /home/student/bin/route-for.sh FILE IP that reads an IPv4 table in ip route format and prints the route the kernel would pick for IP:

  • the longest matching prefix wins (default is 0.0.0.0/0); among equally long ones, the lowest metric (no metric means 0); if still tied, the first in the file,
  • print via <gateway> dev <device> for a route with a gateway, dev <device> for a directly connected one, or just the type for blackhole, unreachable and prohibit routes,
  • if no route matches, print unreachable and exit 1; otherwise exit 0.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Part of Networking and TLS in Practice. Next step: Configure the DNS Resolver

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.