Firewalls, NAT & network segmentation
Design a segmented network with a DMZ and write default-deny firewall rules.
By Invicly Tech, , in Cyber Security Fundamentals. About 8 minutes to read.
In short
Firewalls decide which traffic may pass based on rules, and stateful firewalls track connections so replies are allowed automatically. Segmentation with VLANs and a DMZ limits how far an attacker can move. A default-deny stance only allows what is explicitly needed.
Explained simply
A firewall is a gatekeeper between networks. It reads each connection's source, destination and port, then checks its rule list to decide whether to let it through. Rules are read from top to bottom, and the first match wins.
Segmentation means splitting one big network into smaller zones with firewalls between them. Think of a ship with watertight compartments. If one fills with water, the doors stay shut and the ship stays afloat. If an attacker takes over one laptop, segmentation stops them reaching every server.
NAT (network address translation) lets many devices with private addresses share one public address. Your home router does this. It also means outsiders cannot start connections to your devices unless you set up port forwarding, which is a useful side effect, but NAT is not a full firewall.
The safest firewall stance is default deny. Everything is blocked unless a rule says otherwise. You then add narrow allow rules for what the business really needs, with a note explaining each one.
Press Play on a diagram to walk through it one step at a time.
- 1Internet
Untrusted.
- 2DMZ
Public-facing servers, isolated.
- 3Internal network
Workstations and apps.
- 4Restricted zone
Databases and secrets.
- 1Packet arrives
Source, destination, port, protocol.
- 2Existing connection?
If tracked as established, allow.
- 3Check rules top to bottom
First matching rule wins.
- 4Allow or deny
Act on the matching rule.
- 5No match
Default deny, and log it.
In depth
Writing good rules
A good rule is as narrow as possible: a specific source, a specific destination, a specific port, and a reason. "Allow 10.10.1.0/24 to 10.10.8.15 on TCP 443, for the HR app, ticket CHG-1042" is a good rule. "Allow any to any" is not.
Because rules are processed in order, put specific rules above general ones. End with an explicit deny-all rule that logs what it blocks. Those deny logs are valuable: they show scanning, misconfigured apps and attackers trying to move between zones.
- Narrow source, destination and port
- A reason and owner for every rule
- Specific rules above general ones
- Final deny-all with logging
- Review and remove stale rules regularly
Stateful inspection and egress filtering
A stateful firewall remembers connections it has allowed. If a laptop opens a connection to a website, the reply is automatically allowed back in. You do not need a rule for return traffic, which keeps rule sets short and safe.
Many organisations filter inbound traffic carefully but allow all outbound traffic. That is a gap. Egress filtering (controlling outbound traffic) makes malware's job harder: servers should not browse the internet freely, and only the DNS servers should send DNS queries outward. Blocked outbound attempts are a strong detection signal.
- Laptop to Firewall: Open TCP 443 to website1Open TCP 443 to website
- Firewall to Website: Rule allows it, connection recorded2Rule allows it, connection recorded
- Website to Firewall: Reply packets3Reply packets
- Firewall to Laptop: Matches state, allowed with no extra rule4Matches state, allowed with no extra rule
Designing zones
A typical segmented design has several zones. The DMZ holds internet-facing servers. User networks hold laptops and phones. Server networks hold internal apps. A management network holds admin interfaces, reachable only from admin jump hosts. A guest Wi-Fi network reaches only the internet.
VLANs (virtual LANs) separate zones on shared switches, and a firewall routes between them with rules. The key question for each zone is: what does it truly need to talk to? Everything else is denied.
- DMZ
- Internet-facing servers
- User networks
- Laptops
- Phones
- Server networks
- Internal apps
- Management
- Admin interfaces
- Reached from jump hosts only
- Guest Wi-Fi
- Internet only
Host firewalls and microsegmentation
Network firewalls control traffic between zones, but machines inside the same zone can often talk freely. Host firewalls, like Windows Defender Firewall or nftables on Linux, close that gap by filtering on each machine.
A common example: workstations should never need to connect to each other's SMB port 445. Blocking workstation-to-workstation SMB with a host firewall stops a big share of ransomware and worm spreading. Microsegmentation takes this further with per-application rules, often in cloud or data centre platforms.
Learn it in 4 short steps
About 45m each. Track them with a timer in your plan.
- 1Compare stateless and stateful firewalls~45m
- 2Explain NAT and private ranges~45m
- 3Design VLANs and a DMZ~45m
- 4Write default-deny allow rules~45m
Key points
- Stateful firewalls track connections; stateless judge each packet.
- Default-deny blocks everything not explicitly allowed.
- A DMZ isolates public servers from the internal network.
- NAT lets private addresses share a public one.
Key terms
Tap a card to flip it. 0/4 known
Examples
A default-deny rule set for a small web app
Zones: internet, DMZ (web server 10.0.1.10), app zone (database 10.0.2.20), admin zone (10.0.9.0/24). Read the rules top to bottom. The web server can be reached on 443 from anywhere. Only the web server can reach the database on 5432. SSH is allowed only from the admin zone. Everything else is denied and logged. Note there is no rule allowing the database to reach the internet.
# action source destination port reason
allow any 10.0.1.10 tcp/443 public website
allow 10.0.1.10 10.0.2.20 tcp/5432 web app to database
allow 10.0.9.0/24 10.0.1.10 tcp/22 admin SSH to web
allow 10.0.9.0/24 10.0.2.20 tcp/22 admin SSH to db
allow 10.0.1.10 10.0.0.53 udp/53 DNS via internal resolver
deny any any any default deny (log)Host firewall on a Linux server with ufw
ufw (uncomplicated firewall) is a friendly front end for Linux firewalling. Step 1: Set defaults: deny incoming, allow outgoing (tighten outgoing later). Step 2: Allow SSH only from the admin subnet. Step 3: Allow HTTPS from anywhere. Step 4: Turn on logging. Step 5: Enable and check the status. Always add the SSH allow rule before enabling, or you may lock yourself out of a remote server.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow from 10.0.9.0/24 to any port 22 proto tcp
sudo ufw allow 443/tcp
sudo ufw logging on
sudo ufw enable
sudo ufw status numberedQuick reference
- Rules run top to bottom; first match wins; end with deny all + log
- Every rule: narrow source, destination, port, plus a reason and owner
- Stateful firewalls allow replies automatically; no return rules needed
- Filter outbound too: servers rarely need open internet access
- Block workstation-to-workstation SMB (445) to slow ransomware spread
- NAT hides private addresses but is not a security policy
- Review rules quarterly; remove unused and "temporary" ones
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
On a lab Linux VM, enable ufw with default deny incoming, allow SSH only from your host machine's IP, and confirm the rule list.
- Exercise 2medium
Design zones for a small office with staff laptops, a file server, a printer, guest Wi-Fi and a public website. List the zones and the allow rules between them.
- Exercise 3hard
Audit this rule list and fix it: (1) allow any any tcp/3389, (2) allow 10.0.0.0/8 any any, (3) allow any 10.0.1.10 tcp/443, (4) deny any any.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is my home router's NAT enough protection?
- It blocks unsolicited inbound connections, which helps a lot, but it does not stop malware on your devices from connecting out. Keep devices updated and turn off UPnP if you do not need it.
- What is a next-generation firewall?
- A firewall that understands applications and users, not just IPs and ports. It can, for example, allow a business app but block file sharing tools, and often includes intrusion prevention.
- Do I still need a firewall with zero trust?
- Yes. Zero trust adds identity checks to each request, but firewalls and segmentation still reduce what an attacker can reach and create useful logs.