Firewalls and Network Segmentation
Chapters and transcript
Firewalls and Segmentation Traffic from the internet arrives at the office all day. A visitor wants the company website, and the firewall lets it through. An attacker tries to reach a staff PC, and the firewall blocks it. In this lesson you will learn how firewalls decide, how to write good rules, and how splitting a network into zones stops one infection from spreading everywhere.
What a firewall does A firewall is a system that decides which traffic is allowed through, by comparing each connection against a list of rules. A network firewall sits at the edge, between the office and the internet, and protects many devices at once. A host firewall, such as Windows Defender Firewall or ufw, protects one computer, even on an untrusted network. Good networks use both.
What a firewall does Firewalls also differ in how much they understand. A stateless firewall looks at each packet on its own: source, destination, port and protocol. It remembers nothing. A stateful firewall remembers connections, and almost all modern firewalls work this way. A next-generation firewall adds more checks, like recognising applications, filtering websites by category and blocking known attacks.
What a firewall does Here is a stateful firewall at work. A laptop inside the office opens a connection to a website. The firewall records it. When the reply comes back, it is allowed in automatically. But unrequested traffic from outside is still blocked.
Firewall rules A firewall rule usually has five parts. The direction: inbound or outbound. The source, where traffic comes from. The destination, where it is going. The port and protocol, such as TCP 443. And the action: allow or deny.
Firewall rules Here is a simple rule set for a web server. Rule one: allow HTTPS from anyone. Rule two: allow SSH only from the admin office. Rule three: deny everything else. Most firewalls check rules from top to bottom and use the first rule that matches. So order matters. A broad allow rule above a specific deny rule means the deny rule never runs.
Firewall rules Watch the rules work. A customer asks for the website on port 443. Rule one matches, so it is allowed. The admin office connects with SSH. Rule two matches. Then a stranger tries SSH on port 22. Rules one and two do not match, so rule three denies it.
Default deny That last rule is the most important. Default deny means block everything, then allow only what is truly needed. Each allow rule has a clear business reason and is as specific as possible. The opposite, default allow, blocks only the things you thought of. Attackers look for what you forgot. And rules like allow from any to any are a red flag.
Inbound and outbound Many companies only filter inbound traffic. But outbound filtering matters too. Here, a staff PC is infected. The malware tries to connect out to the attacker server to get commands or send stolen data. The firewall only allows what the business needs, so it blocks this connection. Normal web traffic through the proxy still works.
The DMZ Public servers face constant attacks, so they go in a DMZ, a separate zone between the internet and the internal network. The internet may reach the DMZ only on needed ports, like 443. Now suppose the web server is hacked. The attacker tries to reach the staff PCs. Another firewall rule stops them. Only the web server may talk to one database port.
Segmentation In a flat network, one infected laptop can spread ransomware everywhere. Segmentation splits it into zones, often with VLANs on a managed switch. Traffic between VLANs passes a router or firewall with rules. Staff reach the internet, file server and printers. Finance reaches banking systems. Guests get the internet only. And cameras and smart TVs, often poorly secured, reach only their own management server.
Zero trust Older networks were built like a castle: strong walls, and everyone inside trusted. But attackers often get inside. Zero trust says: never trust, always verify. Being on the office network proves nothing. Each request is checked: who the user is, ideally with multi-factor authentication, which device, and whether it is healthy and updated, and what they may access, following least privilege.
Try it yourself You can safely check your own Windows firewall. Open Command Prompt and run netsh advfirewall show allprofiles state. Each profile, Domain, Private and Public, should show State ON. On Ubuntu, sudo ufw status verbose shows whether ufw is active and its default policies.
Quick check Quick check. An office firewall allows every outbound connection on every port. A staff PC gets infected, and the malware sends data to an unknown server at night. Which change would have helped most? Choose an answer.
Key takeaways Let us put it together. Turn on the host firewall on every computer. Use default deny, and write down why each allow rule exists. Filter outbound traffic, not only inbound. Put public servers in a DMZ, never in the staff network. Separate guests and smart devices from staff and finance. And review the rules a few times a year, deleting old ones.
In the Linux path you used ufw to block incoming connections on one server. This lesson zooms out to the whole network: how firewalls make decisions, how to write good rules, and how splitting a network into zones stops one infection from spreading everywhere.
What a firewall does
A firewall is a system that sits between networks, or on a single device, and decides which traffic is allowed through. It compares each connection against a list of rules.
There are two main places to put a firewall:
- Network firewall: a dedicated device or service at the edge of a network, such as between the office LAN and the internet. It protects many devices at once.
- Host firewall: software on one computer, such as Windows Defender Firewall or ufw on Linux. It protects that one machine, even when it is on an untrusted network.
Good networks use both. If the network firewall misses something, or a laptop leaves the office, the host firewall still protects it.
Firewalls also differ in how much they understand:
- A stateless (packet filtering) firewall looks at each packet on its own: source IP, destination IP, port and protocol. It does not remember earlier packets.
- A stateful firewall remembers connections. If a computer inside the office opens a connection to a website, the firewall records it and automatically allows the replies back in. Unrequested traffic from outside is still blocked. Almost all modern firewalls are stateful.
- A next-generation firewall (NGFW) adds more checks, such as recognising applications, filtering websites by category, and blocking known attacks.
Firewall rules and default deny
A firewall rule usually contains these parts:
| Part | Example |
|---|---|
| Direction | Inbound or outbound |
| Source | 203.0.113.0/24, or any |
| Destination | 192.0.2.10 |
| Port and protocol | TCP 443 |
| Action | Allow or deny |
Most firewalls check rules from top to bottom and use the first rule that matches. Order matters. If a broad allow rule sits above a specific deny rule, the deny rule never runs.
Here is a simple rule set for a web server:
1. Allow TCP 443 from any to 192.0.2.10 (HTTPS website)
2. Allow TCP 22 from 198.51.100.5 to 192.0.2.10 (SSH from admin office only)
3. Deny all from any to any
The last rule is the most important. This approach is called default deny: block everything, then allow only what is truly needed. The opposite, default allow, blocks only things you have thought of, and attackers look for what you forgot.
A few rules of good practice:
- Every allow rule should have a clear business reason. Write it in the rule's comment or description.
- Be as specific as possible. "Allow from any to any" rules are a red flag.
- Review the rules regularly and remove rules for old projects and old servers.
Inbound and outbound traffic
Many companies only filter inbound traffic, the traffic coming in from the internet. But outbound (egress) filtering matters too.
When malware infects a computer, it usually connects out to the attacker's server to receive commands or send stolen data. If the firewall allows every outbound connection on every port, this is easy. If outbound traffic is limited to what the business needs, such as web traffic through a proxy and DNS only to the company's own DNS servers, much malware will fail to connect or will be easier to spot.
Outbound rules also reduce damage if one of your servers is hacked and used to attack others.
The DMZ
Some servers must be reachable from the internet: a public website, a mail server, or a customer portal. These servers face constant attacks. If one is broken into, you do not want the attacker to have a direct path into the office.
The solution is a DMZ (demilitarised zone). It is a separate network zone, between the internet and the internal network:
Internet -> [Firewall] -> DMZ (web server, mail server)
|
-> Internal network (staff PCs, file server, database)
Typical rules:
- The internet may reach the DMZ only on the needed ports, such as 443.
- The DMZ may reach the internal network only for specific needs, such as the web server talking to one database port.
- The internet may not reach the internal network directly.
So if the web server at chaicorp.example is compromised, the attacker is still stuck behind another firewall.
Segmentation and VLANs
Network segmentation means splitting one big network into smaller zones, with rules about which zones can talk to each other. In a flat network, where every device can reach every other device, one infected laptop can spread ransomware to every computer and server.
A common way to segment is with VLANs (virtual LANs). A managed switch can separate its ports into different virtual networks, even though they share the same hardware. Traffic between VLANs must then pass through a router or firewall, where rules can be applied.
A small company might use:
| VLAN | Who is in it | Allowed to reach |
|---|---|---|
| Staff | Employee laptops | Internet, file server, printers |
| Servers | File server, database | Only what each service needs |
| Finance | Accounts team PCs | Banking and accounting systems |
| Guest | Visitors' phones | Internet only |
| Devices | CCTV cameras, smart TVs | Only their own management server |
Cheap cameras and other smart devices are often poorly secured, so they belong in their own zone. Visitors should never share a network with the finance team.
Zero trust
Older networks were built like a castle: strong walls outside, and everyone inside trusted. The problem is that attackers often get inside, through phishing, a stolen password or a rogue device. Once inside, they move freely.
Zero trust is a security model that says: never trust, always verify. Being on the office network does not prove anything. Each time a user or device asks for access, the system checks:
- Who the user is, ideally with multi-factor authentication
- Which device they are using, and whether it is healthy and up to date
- What they are allowed to access, following least privilege
Zero trust is not one product you can buy. It is a direction a company moves in over time, using strong identity checks, segmentation and good monitoring together.
How to defend
Practical steps for a small office or your own devices:
- Turn on the host firewall on every computer and keep it on.
- Use default deny on network firewalls and write down why each allow rule exists.
- Filter outbound traffic where you can, not only inbound.
- Put public servers in a DMZ or in a separate cloud network, never in the staff network.
- Separate guests and smart devices from staff and finance systems.
- Review rules at least a few times a year and delete old ones.
You can check your own Windows firewall status safely. Open Command Prompt and run:
netsh advfirewall show allprofiles state
Each profile (Domain, Private, Public) should show State ON. On Ubuntu, sudo ufw status verbose shows whether ufw is active and what its default policies are.
HANDS-ON LAB
The Rule That Let Them In
An attacker reached a server over RDP from the internet. Find the firewall rule that allowed it.
Check your understanding
Answer every question correctly to complete this lesson. If you miss one, try the quiz again.
1. A firewall has these rules in order: 1) allow TCP 443 from anywhere, 2) deny everything. A packet arrives for TCP port 22. What happens?
2. Why does a company put its public web server in a DMZ?
3. Which idea best describes zero trust?
Locked: answer every quiz question above correctly to complete this lesson.
Spotted a mistake or something unclear? Report a mistake