The five values & implicit deny

A firewall decides packet by packet

Lesson 1 of 20 · 10 min · Module 1: How a firewall thinks

A firewall does not know who you are or what you meant. It reads a few values in each packet and compares them with a list of rules.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Name the five values a firewall rule compares
  • Write a rule that allows one kind of traffic
  • Explain what happens to traffic no rule mentions

The idea

Every rule answers one question: which packets? It names a protocol, a source, a destination, and usually a destination port. Whatever no rule mentions is handled by the default action, and on a firewall that default should be deny.

default deny
allow tcp from 10.0.5.0/24 to 10.0.6.20 port 22

01Read a packet the way a firewall does

A packet carries a protocol (tcp, udp, icmp), a source address, a destination address and, for tcp and udp, a source port and a destination port. These five values are often called the five-tuple. The destination port usually tells you the service: 443 is HTTPS, 22 is SSH, 53 is DNS. The source port is a temporary number the client picked, so rules rarely mention it.

02Allow a little and deny the rest

allow tcp from lan to web port 443 describes one kind of traffic: tcp, from any address in the office network, to the web server, destination port 443. Here lan and web are names for 10.0.1.0/24 and 10.0.2.10; the panel above the editor lists them. With default deny, a packet that matches no rule is dropped. Real devices do the same even when the line is not written out, which is why it is called the implicit deny.

03The same rule on real devices

Each product has its own syntax, but the parts are the ones you just used: who, to whom, which service, and the action.

# Linux nftables
nft add rule inet filter forward ip saddr 10.0.1.0/24 ip daddr 10.0.2.10 tcp dport 443 accept

# FortiGate
config firewall policy
    edit 1
        set srcintf "lan"
        set dstintf "servers"
        set srcaddr "LAN_NET"
        set dstaddr "WEB_SRV"
        set service "HTTPS"
        set schedule "always"
        set action accept
    next
end

# Huawei USG
security-policy
 rule name staff_to_web
  source-zone trust
  destination-zone dmz
  source-address 10.0.1.0 mask 255.255.255.0
  destination-address 10.0.2.10 mask 255.255.255.255
  service https
  action permit

Your turn

Staff in the office network lan need the company website on the server web, over HTTPS (tcp port 443). Add one rule that allows exactly that. Keep default deny for everything else.

What the checks look for

  • Staff reach the website over HTTPS
  • SSH to the web server stays blocked
  • Other networks cannot use the staff rule
  • Everything else is denied by default
Try it in the editor →

Take this with you

A rule names the traffic you want. The default action decides everything you did not name, so keep it on deny.

Go a little further

Change the first line to default allow and run the lab again. Read how many of the test packets now pass without any rule mentioning them.

Learn Firewall Foundations for free

20 short lessons with real code and instant checks.

See the whole course →