online posts 16
labs

Linux and the command line 101

Hands-on Linux for network engineers: find your way around the filesystem, read and edit files, build pipelines with grep, fix permissions, stop a runaway process, log in with SSH keys, write two small Bash scripts, and troubleshoot a web service with ip, ss, curl, dig, traceroute and tcpdump. In your browser, nothing to install.

First lab here? Meet the lab shows how every lab works, once.

Networking 101 showed you how networks work, and its hands-on lab had you type your first commands. This lab is about the place you type them: the Linux command line. It’s where every other lab on this site happens, from Ansible to NetBox to ANTA. It’s also what’s underneath most network gear today, CapeOS included.

You work on a real Linux computer, the codespace itself, and on a small network next to it.

The machines

  your codespace ─ ─ ─ management network 172.80.102.0/24 ─ ─ ─ ws1, srv1, r1

        ws1 ─────────────── r1 ─────────────── srv1
   192.168.10.10/24   .10.1 │ .20.1    192.168.20.10/24
NameWhat it isChapters
codespacethe computer you’re typing on: Debian 12, user vscode, with sudoall of them
ws1a Linux workstation: Debian 13, user netops, password netops-lab4, 6, 8
srv1a Linux server with a small web service on port 8080, and the lab’s DNS server6, 8
r1the router between them: CapeOS Bolt, user admin, password capeos-lab6, 8

The passwords are for these lab machines only: they exist inside your codespace and nowhere else. The management network is how your codespace reaches all three by name (ssh ws1). ws1 and srv1 talk to each other the way real computers do, through r1.

How each task works

The same five parts as the lessons in Networking 101: explain, show, follow along, challenge, then check. You answer some questions in answers/<task>.yml, write a few scripts in scripts/, and change real things: files, permissions, ~/.bashrc, ~/.ssh. make check looks at all of it. The pipelines and scripts you write are run again on files they haven’t seen, so a command that only works on the example won’t pass.

Most of chapters 1 to 7 happen in your codespace’s own terminal, not on a lab machine: the terminal in the lab app’s VS Code tab. Open one with Ctrl+`; it starts in the lab’s folder.

Quick start

  1. Open the lab and sign in with GitHub. The lab is your own copy, in a codespace on your GitHub account's free allowance (what that means). The first start takes a few minutes; coming back takes about one.
  2. The lab opens in your browser: this guide on the left, VS Code on the right, and the network's state at the top. Wait for it to say network up.
  3. Follow task 1.1. Check task, under the guide, tells you when you've got it right.

Finished? Finish lab, top right, deletes the codespace. Left it open? It stops itself after 20 minutes without activity, and Open the lab picks up where you were.

Advanced: run it on your laptop Docker, Git and VS Code
$ git clone https://gitlab.com/networkdoodles-labs/linux-cli-101.git
$ cd linux-cli-101
$ code .            # then: Reopen in Container
$ make check T=1.1

Same dev container, on your own Docker (4 GB of memory is plenty). No dev container? Linux with Docker, containerlab, Python 3 and make runs it with make up, but the tasks assume a Debian user called vscode.

8 chapters · 17 tasks

ch 1 The shell and the filesystemWhere you are, what’s there, and the one tree every file hangs from. Absolute paths, relative paths, and the help every command carries. 35 min lesson 1
  1. 1.1 Where am I?Find out where a new terminal puts you, where your home folder is, which Linux you’re on, and what’s in the lab’s files/ folder, hidden files included. Then use a command’s own help to find an option. 20 min
  2. 1.2 PathsFind a config file in a small tree of sites and racks, write its absolute path, then reach it with relative paths from two other folders, using .. to climb up. 15 min
ch 2 Working with filesRead a router’s log with less, head and tail, watch one grow, write a note in nano, then tidy a messy folder of config backups and find files by name. 45 min lesson 2
  1. 2.1 Read and writeRead a real router log with less, head and tail, search it, watch a file grow with tail -f, then write a note in your home folder with nano. 25 min
  2. 2.2 Tidy upCount files with find, then tidy a messy folder of config backups: make folders, rename the file with a space in its name, delete the empty ones, and move the rest with globs. 20 min
ch 3 Pipes, redirection and grepAnswer questions about a log with one line each: how many, which ones, per interface, most first. Then who keeps failing to log in. 50 min lesson 3
  1. 3.1 PipelinesAnswer questions about r1’s log with one line each: count with grep -c, filter with grep and grep -v, count per interface with cut | sort | uniq -c | sort -rn, and send output to a file with >. 30 min
  2. 3.2 Who's knocking?From r1’s log, count the failed logins, list them per user name, most first, and list every name that failed, once each. One pipeline each, that works on logs it hasn’t seen. 20 min
ch 4 Users, permissions and sudoRead ls -l, set permissions with chmod, use sudo, install a missing tool with apt, then fix a private key ssh refuses and a script that won’t run. 45 min lesson 4
  1. 4.1 Who may do whatRead the permissions in ls -l, find a file only root can read, use sudo, set permissions with chmod, and install a missing tool with apt. 25 min
  2. 4.2 Too open, too closedThree files with the wrong permissions: a private key ssh refuses to use, a script that won’t run, and a notes file anyone can change. Read what each error says, and fix each with chmod. 20 min
ch 5 Processes, environment variables and PATHJobs, ps, top and signals; variables that children inherit and ones they don’t; then a runaway process to stop, and a command of your own that runs from anywhere. 45 min lesson 5
  1. 5.1 Jobs and variablesRun a command in the background, pause and resume it, find it with ps and top; then set an environment variable, see which programs inherit it, and make it last with ~/.bashrc. 25 min
  2. 5.2 RunawayA process is eating a whole CPU and ignores a polite kill. Find it, stop it for good. Then make a command of your own that runs from any folder, by putting its folder on your PATH. 20 min
ch 6 SSH and keysLog in to ws1, check its host key, make a key pair and stop typing passwords. Then short names in ~/.ssh/config, a copy with scp, and a server whose key changed. 50 min lesson 6
  1. 6.1 Your first keyLog in to ws1 over SSH with a password, and check its host key before you trust it. Then make a key pair of your own, put the public half on ws1 with ssh-copy-id, and log in with no password at all. 25 min
  2. 6.2 Short names, a copy, a changed keyGive ws1, srv1 and r1 short names in ~/.ssh/config, copy a file to srv1 with scp, then meet the warning every engineer meets one day: the host key has changed. Find out why, and fix it the right way. 25 min
ch 7 A little Bash scriptingA script that pings every host on a list and fails when one is down, then one that audits a folder of configs for a missing NTP server. 50 min lesson 7
  1. 7.1 Is everyone up?Finish scripts/reach.sh: a script that reads a list of hosts, pings each one, prints up or down, and exits 1 when any of them is down, so other scripts and pipelines can tell. 25 min
  2. 7.2 Audit the configsWrite scripts/audit.sh from scratch: list the configs in a folder that have no ntp server line, exit 1 if there are any, and handle the cases that break most first scripts: names with spaces, an empty folder, and no folder at all. 25 min
ch 8 The network from the command lineFrom ws1: addresses, routes, DNS and hops to srv1. Then a web service that works on the server but refuses everyone else, and the packets of one request with tcpdump. 60 min lesson 8
  1. 8.1 Where does it go?Log in to ws1 and work out how it reaches srv1: its addresses and management interface, its gateway, the DNS server it asks and what it answers, the route for one address with ip route get, and the hops with traceroute. 20 min
  2. 8.2 Refusedsrv1’s web service works when you ask it from srv1, but ws1 gets connection refused. Find out why with curl -v and ss -tlnp, fix the service’s config with sudo nano, restart it, and prove it from ws1. 25 min
  3. 8.3 Catch it on the wireCapture one web request from ws1 to srv1 with tcpdump, save it to a file, read it back, and copy it to the codespace with scp, ready for Wireshark. Read the handshake, the request and the close from the capture. 20 min