One computer can do a lot. Two computers that can talk can do more. A network is just that: computers connected so they can share messages. This lesson starts with two machines and a cable, and ends with the internet, which is a network of networks.
Difficulty: Beginner · Know this first: F11 — Talking to the Computer: Your First Commands
Two laptops, one cable between them. The smallest network that exists. Everything bigger is this idea repeated.
A message crossing the internet spends its time in different places, and the split is not even. The bar below is a teaching example for this lesson, not a measurement from a live system. It shows where 100 units of a message's trip time go, from your laptop to a server far away.
Extra diagram · from scratch to master
Start with two machines and one cable. Add machines one at a time and watch the wiring problem grow, then watch the switch solve it.
Extra diagram · from scratch to master
Follow one message from your laptop to a server far away. Count the boxes it passes, and see where the trip can break.
The simulator below counts cables. Pick a number of computers and watch two numbers: how many cables you need if everyone wires directly to everyone, and how many you need with a switch in the middle. The numbers are exact, not estimates. The lesson is the shape: direct wiring grows fast, and the switch grows slowly.
How many computers share one room. Direct wiring needs one cable for every pair. A switch needs one cable per computer.
Try this: (1) Set computers to 5. Direct wiring needs 10 cables, a switch needs 5, and the switch saves 5. (2) Set computers to 10. Direct wiring needs 45 cables, a switch needs 10, and the switch saves 35. (3) Set computers to 20. Direct wiring needs 190 cables, a switch needs 20, and the switch saves 170. The gap is the whole reason switches exist.
Three questions. No score is saved anywhere — this is just you against the material.
I take the same idea four times here. First I connect two computers. Then I connect a room. Then I connect networks together. Last I run it for the world.
Definition: A network is two or more computers connected so they can share messages. A link is one connection between two machines. An address names a machine on the network so messages can find it.
Types:
Uses: I use this picture every time a machine cannot reach another machine. I ask: is there a link, does each end have an address, and is there a road between them.
Dimensions: At two machines everything is simple and everything is visible. What breaks first is the cable, and I notice it because nothing moves at all. It costs one cable to start. It costs real care to keep the wiring tidy as it grows. The trade is simple: direct wiring is simple and it stops scaling.
Definition: At this level a switch sits in the middle of the room. Every machine wires to the switch, and the switch reads the address on each packet and hands it to the right machine. Messages travel in packets, small pieces that are put back together at the other end.
Types:
Uses: I use this when a new machine joins a room. One cable to the switch, one address, and it is on the network. No rewiring, no knot.
Dimensions: As the room grows, the switch grows with it, and the number of cables grows slowly, one per machine. What breaks is a switch port or a bad cable, and I notice it because one machine goes quiet while the rest keep talking. It costs a switch and a spare port or two. The trade is that the switch is one more box that can fail, and it buys a room that stays tidy.
Definition: At this level routers connect networks together. Each router knows the roads out of its own network and passes packets to the next network. The internet is millions of these networks agreeing to forward each other's packets.
Types:
Uses: I use this when a machine in one network must reach a machine in another. I trace the road hop by hop, router by router, and I find the hop where the packets stop.
Dimensions: At ten times the networks the routing tables grow, and the roads multiply. What breaks is a router that does not know the road, and I notice it because packets die at one hop while every hop before it is fine. It costs a second road for every important trip. The trade is that redundancy costs links and config, and it buys a network that survives a cut cable.
Your own address, from your own machine. Every machine on a network has an address, and yours is one command away. I read it before I debug anything else, because half of all network problems are a machine with the wrong address, or no address at all.
$ ip addr show lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
$ hostname -I
198.19.0.2 fd8b:4f84:7d32:99::2
Every flag in the commands above, letter by letter.
ip addr show: addr picks the object, addresses. show is the action, list them. The lo at the end limits the answer to loopback. Without it, ip addr show lists every interface.hostname -I: -I prints the machine's IP addresses, nothing else. Capital I. It is the quickest way to answer what address am I.ip -br addr is the brief form. One line per interface, with the addresses on the same line. Scripts parse that form. Humans read the long form.Check it: run ip addr show lo, then ip -br addr show lo. The first prints a block of lines. The second prints one line: lo, UNKNOWN, 127.0.0.1/8, ::1/128.
Try it: run both commands. hostname -I prints your addresses on one line. 127.0.0.1 is the loopback address. It always means this machine. If hostname -I prints nothing, the machine has no address, and that is the problem.
The route out. A machine that wants to reach another network asks its gateway. The routing table names that gateway. I read the table when a machine can reach itself but nothing else, because the gateway is the usual missing piece.
$ ip route
default via 198.19.0.1 dev host0
198.19.0.0/30 dev host0 proto kernel scope link src 198.19.0.2
Every flag in the commands above, letter by letter.
ip route prints the routing table, with no flags. The default via line is the gateway. Every packet with no better match goes there.ip route get 127.0.0.1 asks which route a packet to that address would take. The answer names the interface and the source address. When a packet goes the wrong way, route get shows the decision instead of the table.Check it: run ip route, then ip route get 127.0.0.1. The second prints local 127.0.0.1 dev lo. The packet stays on loopback.
Try it: run ip route. The first line names your default gateway. If there is no default line, the machine has no way out. It can talk to itself and to its own small network, and nothing else.
Definition: At this level the network is a system with owners, monitoring, and capacity planning. Every link is watched. Every important road has a spare. Addressing is planned, not improvised. When a link fails, traffic moves on its own and someone is told.
Types:
Uses: I use this when the network carries real users and real money. It is also how I review a network I did not build: I ask which links are watched, which roads have spares, and when the last failover was tested.
Dimensions: At a hundred times the traffic the links fill up and the planning matters more than the hardware. What breaks is the link nobody watched, usually the one that was quiet for a year, and I notice it from the alert, not from a user. It costs monitoring, spares, and drills. The trade is that the watching costs effort every week, and it buys a network that fails quietly instead of loudly.
The machine that cannot reach anyone. A connection can fail at the far end while your own machine is fine. I tell the two apart by testing my own machine first. If my address is set and my gateway is there, the problem is beyond my machine, and I stop changing my own settings.
$ curl -s -o /dev/null -w "%{http_code}\n" --max-time 3 http://127.0.0.1:9/
000
$ echo $?
7
Every flag in the commands above, letter by letter.
curl -s: -s means silent. It hides the progress meter. Without it, curl prints download progress to the screen, which ruins a script's output.curl -o /dev/null: -o writes the body to a file. Here the file is /dev/null, the black hole, so the body is thrown away. I only want the status code, not the page.curl -w "%{http_code}\n": -w prints a custom line after the transfer. %{http_code} is the status code. Without -w, a discarded body prints nothing at all.curl --max-time 3: --max-time 3 gives up after 3 seconds. Without it, curl waits as long as the server takes. On a dead port, the answer is 000, which means no response came back.echo $? prints the exit code. 7 means curl could not connect. The code and the 000 tell the same story in two places.curl -sS is silent but still shows errors. With plain -s, a failed connection prints nothing. With -sS, it prints curl: (7) Failed to connect. In a script I use -sS, so failures are visible and successes stay quiet.Check it: run the command above with -s, then with -sS. The first prints 000 and nothing else. The second prints the same 000, plus curl: (7) Failed to connect to 127.0.0.1 port 9.
Try it: run the command above. Port 9 on your own machine has nothing listening, so curl fails with code 000 and exit code 7, connection refused. The machine is fine. The service is not there. That distinction saves you from fixing a machine that is not broken.
What the bits ride on. A message needs something to travel on. That something is called transmission media. The medium changes. The job does not: move bits from one machine to another.
Copper twisted pair is the office cable. Thin copper wires, twisted in pairs, inside one jacket. That is the cable between your laptop and the wall socket. It is cheap and easy to fix. One run covers about 100 metres. Past that the signal fades.
Coax is the TV cable. One thick copper core with shielding around it. It carried cable TV into homes, and it still carries the internet into some homes for the last run from the street. It reaches further than twisted pair, and it costs more.
Fibre is glass and light. A thin glass strand carries pulses of light, not electricity. It is fast, and it runs for kilometres without fading. The undersea cables between continents are fibre. It costs more to install and to repair, and a sharp bend can break it.
Wireless is radio. Wi-Fi and mobile data carry bits as radio waves through the air. No cable to trip over. The air is shared, so walls, distance, and neighbours all slow it down. The last step to a phone is almost always wireless, even when the rest of the road is fibre.
Pick by distance and place. Inside a building, copper. Between cities, fibre. To a phone in your hand, wireless. When a link is slow, I ask which medium it is on first, because the fix for a bad cable is not the fix for a weak radio signal.
Try it: look at how your machine connects. A cable with a clip on the end means copper Ethernet. No cable means wireless. Follow the cable to the wall if you can. That cable is the first hop of every message you send.
Wi-Fi and cable do the same job. A cable carries signals as electricity. Wi-Fi carries them as radio. The cable is faster and steadier. Wi-Fi is freer and noisier. When a connection is slow, I ask which one it is on, because the answer changes what I check first.
LAN and WAN are just sizes. A LAN is a local network: a room, a building, a home. A WAN is a wide network: a city, a country, the world. The boxes are the same. The distances change, and distance is what makes the middle of the trip cost the most time.
Bandwidth and latency are different things. Bandwidth is how much can travel at once. Latency is how long one packet takes. A wide road with slow traffic has high bandwidth and high latency. A narrow road with fast traffic has low bandwidth and low latency. People confuse them constantly, and the fix depends on which one is actually wrong.
The internet is not one thing, and nobody owns it. It is an agreement between networks to forward each other's packets. That agreement is the addressing and the forwarding rules. Everything else, every app and every site, is built on top of that agreement.
At 10x the machines, the addressing breaks first. Handing out addresses by hand works for five machines and fails for fifty. That is why networks get a service that hands out addresses automatically, and why that service is one of the first things I set up in any new network.
At 100x, the design changes. One switch becomes many, arranged in layers. The core carries traffic between rooms. The edge carries traffic to the machines. And every important link gets a spare, because at that size a single failed link is no longer a nuisance. It is an outage.
Try it: name your address and your gateway. Run hostname -I and ip route. Write down your address and the gateway from the default via line. Those two numbers are the start of every network debug you will ever do. If either one is missing, you found the problem before you touched anything else.
$ hostname -I
198.19.0.2 fd8b:4f84:7d32:99::2
$ ip route
default via 198.19.0.1 dev host0
198.19.0.0/30 dev host0 proto kernel scope link src 198.19.0.2
One morning the office printer vanished from the network. Nobody could print. Everyone blamed the printer. I restarted it twice. I reinstalled the driver on my own laptop. Nothing changed. The printer was fine. The switch port it was plugged into had died overnight, quietly, with no light and no complaint.
Three things. First, I label every switch port now, so a dead port can be named in one sentence. Second, I keep two spare ports free on every switch, because a dead port with no spare is a longer outage. Third, I check the link light before I reinstall anything. The cheapest check is usually the right one, and I keep learning that the expensive way.
Design the network for a 12-person office in one room. Twelve laptops, one shared printer, and one connection to the internet. Everyone needs to reach the printer and the internet. The budget is small and the room is one open space.
Twelve laptops plus one printer is 13 devices, so a 16-port switch leaves 3 spare ports. One cable from the switch to the router, and the router to the internet connection. Direct wiring for 13 devices would need 78 cables; the switch needs 13. I run cables to the desks for the machines that never move, and Wi-Fi for the laptops that do. The addressing is automatic, one address per device, handed out by the router.
Cables buy speed and steadiness and cost flexibility: a desk with a cable cannot move. Wi-Fi buys movement and costs speed and interference. One switch buys simplicity and costs a single point of failure: if it dies, the whole room goes quiet. Two switches buy survival and cost money and config. For 12 people, one switch and a spare in the cupboard is the right trade.