Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

Set-up · 15 minutes

Set up your networking lab

After this lesson you can
  • Create the lab folder of the networking course
  • Check that the tools of the course are on your machine
  • Know which steps of the course need root and which tools are optional
Lab files of this lesson (1)

The lab folder as it stands after this lesson. Unzip it in ~/krlab.

More

The zip holds every file that the course has printed up to here. Type the code yourself first: you learn more.

What you need

A Linux machine that you own, with a terminal. You do not need root, a network or an account for most of the course. All the servers in the course run on your own machine, on the loopback address 127.0.0.1, and use the ports 8000 to 8099. You never test a system that is not yours.

You need basic Python: variables, functions, loops, files and f-strings (the Python course, first lessons). You also meet with, try and except (Python course, lessons 4 and 5). Some servers are written with a class: you run them, you do not write one. The course explains the network modules socket, struct, ssl and ipaddress when they first appear.

The course does not teach SSH, Wi-Fi security or a Linux firewall in depth: the Linux course, Part 3, covers the firewall and SSH. Part 3 also shows the same shell commands for addresses, routes and names, and Part 4, lesson 6, repairs a faulty network. Here the commands are tools to read packets and to build your own checks: skim lesson 2 if you know them.

The course uses these tools. The script of this lesson checks them.

ToolUsed forNeeded
python3 (3.12 or newer)Servers, clients and the tools that you writeYes
curlSend web requests and read the answersYes
opensslMake and read certificatesYes
ipRead addresses and routesYes
ssList listening and connected socketsYes
pingTest that the network stack worksYes
getentAsk the resolver of the systemYes
digSend DNS questions (lesson 7)Yes
tcpdumpCapture packets and read capture files (lessons 3 and 10)Optional
unshare, nsenterMake a private test network (lessons 3, 4, 10 and 12)Optional
nft, sysctlWrite firewall rules and turn on forwarding in the private network (lesson 12)Optional

The optional tools are not part of the check line. tcpdump needs root on your real network. In lesson 3, unshare gives you a private network in which you are root, so tcpdump and nft work without sudo. Lessons 4, 10 and 12 use the same method. Some systems forbid that (see "If it fails"). Then you skip those steps, and lesson 10 gives a recorded capture instead.

One step needs root (the administrator): the capture on your real network in lesson 10. It is marked "(needs root)". No answer that the site checks depends on it, so no output is shown. Run it only on a machine that you own.

Set it up

1. Make the lab folder

mkdir (make directory) creates a directory. The option -p (parents) also creates the directories above it, and gives no error if it exists. cd (change directory) moves you into it, and pwd (print working directory) shows where you are. The sign ~ means your home directory. Every later lesson starts in this folder.

mkdir -p ~/krlab/networking
cd ~/krlab/networking
pwd
/home/you/krlab/networking

2. Write the check script

Save the text below in the file labcheck.sh in this folder. Use any text editor, for example nano labcheck.sh. The script is a shell script. The function need asks the shell if a program exists (command -v), prints one line and counts the result. The last line prints how many of the needed tools it found.

labcheck.sh

#!/bin/sh
# Checks the tools of the networking course. One line for each tool.
ok=0
total=0

need() {
    total=$((total + 1))
    if command -v "$1" >/dev/null 2>&1; then
        echo "ok       $1"
        ok=$((ok + 1))
    else
        echo "MISSING  $1"
    fi
}

total=$((total + 1))
if python3 -c 'import sys; sys.exit(sys.version_info < (3, 12))' 2>/dev/null; then
    echo "ok       python3 (version 3.12 or newer)"
    ok=$((ok + 1))
else
    echo "MISSING  python3 (version 3.12 or newer)"
fi

for tool in curl openssl ip ss ping getent dig; do
    need "$tool"
done

for tool in tcpdump unshare nsenter nft sysctl; do
    if command -v "$tool" >/dev/null 2>&1; then
        echo "ok       $tool (optional)"
    else
        echo "absent   $tool (optional)"
    fi
done

if unshare -Urn true 2>/dev/null; then
    echo "ok       private network (unshare -Urn)"
else
    echo "absent   private network: the labs of lessons 3, 4, 10 and 12 need it"
fi

echo "lab ready: $ok of $total"

[ "$ok" -eq "$total" ]

If you want to skip typing, or start at a later lesson, take the files from the lab zip: the course page has a button "Lab files". Save the zip in ~/Downloads. If unzip is missing, install it with sudo apt install unzip. Then run cd ~/Downloads && unzip files.zip && cd networking, and sh kr-lab.sh 00-set-up-your-lab ~/krlab/networking. The same command with the name of another lesson builds the lab folder as it stands after that lesson, for example 15-scenario-test. The script replaces files of the same name, so keep your own changes in a copy with another name.

3. Run it

sh runs a script with the shell. The script needs no root.

sh labcheck.sh
ok       python3 (version 3.12 or newer)
ok       curl
ok       openssl
ok       ip
ok       ss
ok       ping
ok       getent
ok       dig
ok       tcpdump (optional)
ok       unshare (optional)
ok       nsenter (optional)
ok       nft (optional)
ok       sysctl (optional)
ok       private network (unshare -Urn)
lab ready: 8 of 8

If an optional tool says absent, that is fine for now. Before you start, run ss -tln | grep -E ':80[0-9][0-9]'. If a program of yours uses a port in that range, stop it for the course.

Check your lab

Run sh labcheck.sh again and read the last line. Type it into the box.

If your last line has a smaller number, the lab is not ready. Go to the next heading.

If it fails

  • A line says MISSING. Install the tool with the package manager of your system. On Debian, Ubuntu and Kali: sudo apt install curl openssl iproute2 iputils-ping libc-bin dnsutils python3. The package of ss and ip is iproute2, and the package of ping is iputils-ping. Run the script again.
  • ip, nft or sysctl is missing, but you know it is installed. It lives in /usr/sbin, and on some systems that folder is not in your PATH. Run PATH=$PATH:/usr/sbin:/sbin sh labcheck.sh.
  • The private network line says absent. unshare -Urn true is refused, so your system limits user namespaces. On a machine that you own you may run the labs as root instead, for example sudo unshare -n sh vlanlab.sh arp.sh. Files that root makes belong to root, so run sudo chown -R $USER ~/krlab/networking afterwards, or a later run without sudo cannot overwrite them. Ubuntu 24.04 and later block unshare -Urn for ordinary users by default. There you may lift the limit with sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0. This lowers a protection of the whole system until the next reboot, so do it only on a lab machine.
  • Python is older than 3.12. Install a newer python3. The course is tested with 3.12 and newer.
  • dig is missing. Install it with sudo apt install dnsutils (the package may be called bind9-dnsutils). On Fedora the package is bind-utils.
  • A later lesson says that a port is busy. Another program uses that port. Find it with ss -tlnp | grep 8000 (change the number), and stop that program, or wait until the old server of the course has stopped.
  • The script does not run at all. Check that the file is called labcheck.sh, that you are in ~/krlab/networking, and that you started it with sh labcheck.sh.