Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 11 of 46

Lesson: SubnetsSwitch
โ† Linux Foundations

Network operations

Subnets

Understand what a subnet is, what a subnet mask does and why networks are divided.

A subnet is a smaller network carved out of a larger block of addresses. Hosts in the same subnet reach each other directly. Traffic to another subnet goes through a router.

The subnet mask

A mask is 32 bits: ones for the network part, then zeros for the host part. /24 and 255.255.255.0 mean the same thing.

address  192.168.1.50   11000000.10101000.00000001.00110010
mask     255.255.255.0  11111111.11111111.11111111.00000000
network  192.168.1.0    11000000.10101000.00000001.00000000

The network address is found with a bitwise AND: a bit stays 1 only where both the address and the mask have a 1.

Network and broadcast addresses

In an ordinary IPv4 subnet, two addresses are not given to hosts:

  • All host bits 0: the network address, here 192.168.1.0.
  • All host bits 1: the broadcast address, here 192.168.1.255. A packet sent to it is meant for every host in the subnet.

So a /24 has 256 addresses and 254 usable ones. Point-to-point links using /31 are a special exception, where both addresses are used.

Why divide a network?

  • Smaller broadcast domains: broadcasts stay inside their subnet.
  • Control: a router or firewall between subnets can limit what passes.
  • Organisation: servers, staff and guests each get their own range.

Splitting alone does not secure anything. You need filtering rules between the subnets. On switches, subnets are often paired with VLANs, described in the VLAN guide.

Local or not?

A host applies its own mask to decide. With 192.168.1.50/24:

  • 192.168.1.200 is in the same subnet, so it is reached directly.
  • 192.168.2.10 is not, so the packet goes to the gateway.

You can ask Linux:

$ ip route get 192.168.2.10
192.168.2.10 via 192.168.1.1 dev eth0 src 192.168.1.50 uid 1000
    cache

The word via shows that a gateway is involved. For a local address it is absent, unless some more specific route says otherwise.

A wrong mask causes confusing faults: some addresses work and others do not, because the host misjudges what is local.

Try it

Run ip -4 address and note your prefix. Work out your network and broadcast addresses by hand. Then run ip route get for one address inside that range and one outside, and look for via.

Check your understanding

Subnets

All 4 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.