Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

8.3 (5 of 5): Firewalls, segregation and monitoring

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

55 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

The guard at the gate

A big office has a guard at the gate. The guard has a list. Delivery vans may come in. Visitors need a pass. Nobody may carry a box out without a note.

A computer network (linked computers) has a guard like that. It checks everything that comes in and goes out, using a list of rules.

Key words

WordWhat it meansExample
NetworkComputers and devices linked together.a school network
FirewallA guard that allows or blocks network traffic using rules.a gate with a list
InboundTraffic coming into your network.a visitor to your website
OutboundTraffic going out of your network.a worker opening a web page
PortA numbered door on a computer for network traffic.port 443 for secure web pages
IP addressThe number that names a device on a network.192.168.1.20
SegregationKeeping parts of a network apart.a guest network and a staff network
Network monitoringWatching network traffic and logs for problems.a screen of alerts
Port scanningChecking which ports are open on a computer.a list of open doors

The cells students fill in are left blank in this preview.

Quick check: in or out?

Have a go

Quick check: in or out?

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

A firewall between two networks

flowchart LR
  internet([The internet]) -->|inbound traffic| fw{Firewall rules}
  fw -->|allowed| office[Company network]
  fw -.->|blocked| bin[Dropped]
  office -->|outbound traffic| fw

Four kinds of firewall rule

Kind of ruleIt decides byExampleWhy use it
Traffic directionWhether it is inbound or outboundBlock all inbound traffic unless asked forStrangers cannot start a chat with your computers
Traffic typeThe kind of traffic, such as web pages or emailAllow web traffic. Block file sharingStops kinds of traffic the business does not need
ApplicationWhich program sends itBlock a game, allow the work programStops unwanted programs sending data out
IP addressWhere it comes from or goes toBlock a list of addresses known to attackShuts out sources that are known to be bad

The cells students fill in are left blank in this preview.

In a rule list, the first match wins

RuleActionDirectionPortMeaning
1AllowInbound443Visitors may reach secure web pages
2DenyInbound23Nobody may use door 23
3AllowOutboundanyStaff may go out to the internet
4DenyEverything elseanyDefault: block what is not listed

The cells students fill in are left blank in this preview.

Which rule would you write?

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Extra: Some real port numbers

PortWhat uses itUsual rule
443Secure web pages (HTTPS)Allow
80Web pages that are not secureOften sent on to 443
22Secure login to a computer from far awayAllow only for staff
23Telnet, an old login that sends passwords as plain textDeny
3389Remote desktop (using a computer from far away)Deny from the internet

The cells students fill in are left blank in this preview.

Try it: first match wins

Code: python
rules = [["allow", "in", 443], ["deny", "in", 23], ["allow", "out", "any"]]

def decide(direction, port):
    for rule in rules:
        if rule[1] == direction and (rule[2] == "any" or rule[2] == port):
            return rule[0]
    return "deny"

print(decide("in", 443))
print(decide("in", 23))
print(decide("in", 8080))

# Add a new rule at the start to allow port 8080 and run it again.

Make a free account to save your work and track your progress.

Keep the parts apart

Segregation means keeping parts of a network apart. If an attacker gets into one part, they cannot walk into the rest.

Three ways: virtual (one set of cables, split by software), physical (separate cables and network boxes), and offline (no connection at all).

A segregated network

flowchart TD
  net([Internet]) --> fw{Firewall}
  fw --> guest[Guest Wi-Fi zone]
  fw --> office[Office zone]
  fw --> servers[Server zone]
  office --> servers
  vault[(Offline vault: no network)]

Three ways to segregate

WayHowBenefitDrawback
VirtualSoftware splits one network into zonesCheap and easy to changeA software mistake can join zones again
PhysicalSeparate cables and network boxesStrong splitCosts more. Harder to change
OfflineNot connected to any networkCannot be attacked over a networkSlow. Data moves by hand

The cells students fill in are left blank in this preview.

Your turn: build a tiny firewall

Build a tiny firewall. The first function reads a list of rules: the first match wins, and the default is deny. The second blocks addresses on a list. The third says if two zones may talk. Press Run Tests.

Code: python
def decide(rules, direction, port):
    # rules is a list of rules, in order. Each rule is a list: [action, direction, port].
    # For example ["allow", "in", 443].
    # A port of "any" matches every port. The FIRST rule that matches wins.
    # If no rule matches, the answer is "deny" (default deny).
    return ""


def ip_allowed(ip, blocked_ips):
    # False if the address is on the blocked list.
    return True


def can_talk(zone_a, zone_b, allowed_pairs):
    # allowed_pairs is a list of pairs, like [["office", "servers"]].
    # The two zones in a pair may talk, in either direction.
    # Give back True only if the two zones are the same, or the pair is allowed.
    return True

Make a free account to save your work, or press Start lab to work through the whole lesson.

Monitoring spots strange traffic

Network monitoring means watching traffic and logs all the time. It spots strange things: many wrong passwords, a big file going out at 3am, or a device talking to a bad address.

Port scanning finds open ports. Owners scan their own network to shut doors that should be closed. Attackers scan too.

Extra: Before the lab: the one rule

Warning

The next lab gives you copied logs from a made-up attack, on your own machine. Press Start the lab on the bar at the top and wait until it is running. Never scan or probe a network that is not yours. It can break the law, such as the Computer Misuse Act 1990. It can also break college rules.

Extra: 1. See the evidence files

Command
find case -type f

A command for the lesson’s lab terminal. It is shown here and not run.

Extra: 2. Read a few log lines

Command
head -n 5 case/var/log/auth.log

A command for the lesson’s lab terminal. It is shown here and not run.

Extra: 3. Count the failed passwords

Command
grep -c "Failed password" case/var/log/auth.log

A command for the lesson’s lab terminal. It is shown here and not run.

Scenario: what went wrong?

Have a go

Scenario: what went wrong?

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Key words crossword

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

Final check

Have a go

Final check

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.