Module 12 · Networking 45 min

Networking sounds complicated. It really isn't. Underneath, it's just computers sending little messages to each other. This module shows you how to check if your computer is online, how to find what's wrong when it isn't, and how to log into another computer over the internet — all from the terminal.

By the end of this module, you will:

  • Check IP address, gateway, and DNS configuration from the terminal
  • Diagnose network connectivity problems using a five-step sequence
  • Connect to a remote computer using SSH
  • Transfer files between computers using scp and rsync
  • Configure the ufw firewall to allow or block ports
  • Identify which services are listening on which ports with ss
💼

Coming from Windows? Here's the swap

On Windows you opened Settings → Network & Internet, or you typed ipconfig in the Command Prompt. On Linux you type ip addr and ip route instead. The ideas are the same — your IP address, your router (also called a gateway), and DNS — just a different way to look at them.

Lesson 12.1
Your IP address — your computer's home address

Every computer on a network has an IP address. Think of it like the address of your house. When you post a letter, you write your address on the envelope so the reply can find its way back. Your computer does the same thing — it writes its IP address on every message it sends, so the answer knows where to go.

On Windows you typed ipconfig to see your address. On Linux you type ip addr. The result looks a bit different but it tells you the same thing. Look for the line that says inet — that's your IP address. Ignore the lo bit at the top; that's just your computer talking to itself, which is normal.

Checking your network — the basics
# See your IP address (like ipconfig on Windows)
user@ubuntu:~$ ip addr
1: lo: <LOOPBACK> ... ← ignore this one (computer talking to itself)
2: eth0: <BROADCAST> ...
inet 192.168.1.45/24 ... ← THIS is your IP address

# Shorter version — just show the addresses
user@ubuntu:~$ ip addr show eth0

# See your public IP address (what the internet sees)
user@ubuntu:~$ curl -s ifconfig.me
82.45.123.67

# Is the internet working? Test by pinging Google's servers
user@ubuntu:~$ ping -c 4 google.com
64 bytes from 142.250.180.46: icmp_seq=1 ttl=117 time=12.4 ms
64 bytes from 142.250.180.46: icmp_seq=2 ttl=117 time=11.8 ms
4 packets transmitted, 4 received, 0% packet loss
# "0% packet loss" = internet is working fine

# See the routing table — how data leaves your computer
user@ubuntu:~$ ip route
default via 192.168.1.1 dev eth0 ← your router (gateway)
192.168.1.0/24 dev eth0 ... ← your local network
Key TakeawayThree quick checks, in this order: ip addr (what's my address?), ping -c 4 google.com (can I reach the internet?), ip route (is my router set up right?). Run these three whenever the network isn't working — the one that fails tells you what's broken.
Lesson 12.2
SSH — logging into a computer that isn't in front of you

Imagine you need to check something on a computer in another building, another city, or another country. You don't want to walk over and sit at it. SSH (it stands for Secure Shell) lets you open a terminal on that far-away computer, as if you were sitting right in front of it. It's a private encrypted tunnel — nobody else on the internet can see what you type or what comes back.

On Windows you might have used a program called PuTTY to do this. On Linux and macOS, SSH is already there — you just type it. The basic command is ssh username@serveraddress. The very first time you connect to a new computer, it shows you a "fingerprint" and asks you to confirm — that's a safety check, to make sure you're connecting to the right machine. Type yes.

SSH — connecting to remote computers
# Basic connection — username@server address
user@laptop:~$ ssh john@192.168.1.100
The authenticity of host '192.168.1.100' can't be established.
Are you sure you want to continue connecting? (yes/no): yes
john@192.168.1.100's password: ****
Welcome to Ubuntu 24.04 LTS
john@server:~$
# Notice the prompt changed — you are now ON the remote computer

# Connect to a server on a non-standard port
user@laptop:~$ ssh -p 2222 john@myserver.com

# Log out — goes back to your own computer
john@server:~$ exit
Connection to 192.168.1.100 closed.
user@laptop:~$
# Notice the prompt changed back — you are home again

SSH keys — getting in without a password. Typing your password every time you connect gets boring fast. You can set up an SSH key — think of it as a digital key-card that your laptop shows the server automatically. The server recognises your key-card and lets you in without asking for a password. It's also much safer than a password. We'll cover how to set this up in Module 13.

Key TakeawaySSH lets you drive another computer from your own terminal. The command is ssh username@ipaddress. The first time you connect, the "are you sure?" question shows up — type yes. To come back to your own computer, type exit.
Lesson 12.3
Finding a network problem, one step at a time

When the network stops working, most people restart the computer and cross their fingers. That fixes it maybe 30% of the time. The other 70% of the time there's a real reason — and finding it only takes about five minutes if you ask the right questions in the right order.

Network problems stack up like a ladder. Start at the bottom and work your way up. First, does your computer have an IP address at all? Then, can it reach your router? Then, can it reach the wider internet? Then, does DNS work? (DNS is the thing that turns a name like "google.com" into the number that computers actually use.) Each step narrows down where exactly the problem is.

Network diagnosis — five steps in order
# STEP 1: Does my computer have a network address?
user@ubuntu:~$ ip addr | grep "inet "
inet 127.0.0.1/8 ... ← only this = no network connection
inet 192.168.1.45/24 ... ← good, computer has an address

# STEP 2: Can I reach my router? (the box in your office/home)
user@ubuntu:~$ ping -c 2 192.168.1.1
2 packets transmitted, 2 received → router is reachable
2 packets transmitted, 0 received → cannot reach router

# STEP 3: Can I reach the internet by IP address?
user@ubuntu:~$ ping -c 2 8.8.8.8
2 packets transmitted, 2 received → internet connection works
2 packets transmitted, 0 received → router not forwarding traffic

# STEP 4: Does name translation work? (can google.com be found?)
user@ubuntu:~$ ping -c 2 google.com
2 packets transmitted, 2 received → everything works!
# If step 3 worked but step 4 fails → DNS problem

# STEP 5: What DNS server am I using?
user@ubuntu:~$ cat /etc/resolv.conf
nameserver 8.8.8.8 ← Google's DNS (good choice)
nameserver 192.168.1.1 ← your router's DNS

Checking which doors are open. A port is like a door on your computer. Different programs use different doors. Web servers use door 80 (the normal one) and 443 (the secure one). SSH uses door 22. If a door is closed, that program can't be reached. Type ss -tlnp to see which doors are open on your computer right now — that tells you straight away whether a program is actually listening for visitors.

Checking open ports — which doors are open?
# See all open ports and what service is using each one
user@ubuntu:~$ ss -tlnp
State Recv-Q Send-Q Local Address:Port Process
LISTEN 0 128 0.0.0.0:22 sshd ← SSH is accepting connections
LISTEN 0 128 0.0.0.0:80 nginx ← web server is running
LISTEN 0 128 127.0.0.1:3306 mysqld ← database (local only)

# Check if a specific port is open on another server
user@ubuntu:~$ nc -zv myserver.com 80
Connection to myserver.com 80 port [tcp/http] succeeded! ← port is open
nc: connect to myserver.com port 80 failed: Connection refused ← port closed
Key TakeawayNetwork problems have an order: no IP → no router → no internet → no DNS. Check each one with ping. Use ss -tlnp to see which programs on your own computer are accepting visitors. Go top to bottom — the first step that fails is the one to fix.
Lesson 12.4
Copying files between computers

Sometimes you need to send a file from your laptop to a server, or pull one down from a server to your laptop. Linux gives you two tools for this that Windows doesn't have built in: scp (Secure Copy — copy and paste, but over the network) and rsync (a smarter copy that only sends the bits that have actually changed).

Think of scp like sending an email attachment — the whole file goes every time. Think of rsync like Google Drive syncing — it only uploads what's new or changed since last time. For big files, or backups you run every night, rsync saves a huge amount of time.

scp and rsync — moving files over the network
# scp — copy a file TO a server
user@laptop:~$ scp report.pdf john@192.168.1.100:/home/john/documents/
report.pdf 100% 2MB 8.4MB/s 00:00

# scp — copy a file FROM a server to your computer
user@laptop:~$ scp john@192.168.1.100:/var/log/nginx/error.log .
error.log 100% 14KB 3.2MB/s 00:00

# rsync — smart sync (only transfers what changed)
user@laptop:~$ rsync -avz /home/john/documents/ john@server:/backup/documents/
sending incremental file list
new-report.pdf
sent 2,401 bytes received 35 bytes
# Only the new-report.pdf was sent — everything else was already synced
Key TakeawayUse scp when you just need to send one file (like an email attachment). Use rsync when you're backing up or syncing a whole folder — it only sends what's changed. Both go over SSH, so you'll need the same login you'd use to SSH in.
Lesson 12.5
Firewall basics with ufw — locking the front doors

Every computer on a network has dozens of "doors" called ports. Each port is where a different program waits — port 22 is SSH, port 80 is web pages (HTTP), port 443 is secure web pages (HTTPS), port 3306 is a database called MySQL. A firewall is the bouncer at each door, deciding who's allowed in.

On Windows you've used Windows Defender Firewall, with its panel of tick-boxes. On Linux the standard tool is ufw — short for "Uncomplicated Firewall". The name is honest: it gives you a friendly front for Linux's deeper firewall, so you don't have to write tricky low-level rules.

ufw — the everyday commands
# Check whether the firewall is on (it's off by default on Ubuntu Desktop)
user@ubuntu:~$ sudo ufw status
Status: inactive

# Allow SSH BEFORE you enable the firewall, or you'll lock yourself out remotely
user@ubuntu:~$ sudo ufw allow ssh
Rule added

# Turn the firewall on
user@ubuntu:~$ sudo ufw enable
Firewall is active and enabled on system startup

# Allow a specific port (e.g. a web server you're running)
user@ubuntu:~$ sudo ufw allow 443/tcp

# Block a port
user@ubuntu:~$ sudo ufw deny 23 # block telnet entirely

# See all current rules with numbers, then delete one
user@ubuntu:~$ sudo ufw status numbered
user@ubuntu:~$ sudo ufw delete 3 # remove rule #3

The big mistake to avoid: never turn ufw on for a remote server before allowing SSH. ufw blocks every incoming connection by default — and that includes the SSH connection you used to log in. You'll be kicked out and locked out. The only fix is to plug in a keyboard and screen directly, which you probably can't do for a cloud server.

Key TakeawayThree commands handle 90% of the work: sudo ufw allow ssh, sudo ufw enable, sudo ufw status. On a remote machine, always allow SSH first — then turn the firewall on.
Lesson 12.6
What's listening on my computer right now? (ss)

Before you open a door in your firewall, you should know what's on the other side of it. The question "what programs are listening on which doors right now?" is answered by ss. (It's the modern replacement for an older command called netstat.) The first time you run it can be a real eye-opener — sometimes a bit alarming.

ss — listening sockets
# Show every TCP and UDP port that's listening, with the program name
user@ubuntu:~$ sudo ss -tulnp
Netid State Local Address:Port Peer Process
tcp LISTEN 0.0.0.0:22 * users:(("sshd",pid=812))
tcp LISTEN 127.0.0.1:631 * users:(("cupsd",pid=901))
udp UNCONN 0.0.0.0:5353 * users:(("avahi-daemon"))

# What the flags mean:
-t TCP sockets -u UDP sockets
-l listening only -n numeric (no DNS lookup, faster)
-p show the program (needs sudo to see all)

Look closely at the Local Address column. 0.0.0.0:22 means "listening on every network, on port 22" — anyone on the network can try to connect. 127.0.0.1:631 means "listening only on this computer itself" — safe, nobody outside can reach it. If you spot something on 0.0.0.0 that you didn't expect, you should be able to explain exactly why it's there.

Key Takeawaysudo ss -tulnp is your one-line answer to "what on my computer is reachable from outside?" Run it whenever you install a new server-style program — lots of them start up on their own, and you want to know what's listening.