Wiki DE Start in the browser

Wiki › Protocols

Firewall rules (packet filter)

Rules from top to bottom, default rule, stateful or stateless – how a router or firewall decides what may pass.

Layer
3 und 4
See an example
2 demos

A rule

Every rule checks properties of a packet and decides:

PropertyExample
Actionallow or deny
ProtocolTCP, UDP, ICMP or all
Destination port80 for web, 53 for DNS
Source, destinationany, an address, a network such as 192.168.1.0/24
Inputinterface or zone the packet comes in on

Rules apply from top to bottom; the first match decides. If none matches, the default rule applies. Safe is “deny everything that is not allowed”.

Stateful

A stateful firewall remembers allowed connections. Replies to them come back without a rule of their own, as do related ICMP error messages. A stateless firewall needs a rule for each direction; replies from web servers then come back e.g. from port 80 to a high port.

Packets to the router itself

A router filters forwarded packets. Packets to the router itself (SSH, ping) are only checked by a rule that explicitly names one of its addresses as destination, e.g. Deny TCP any → 203.0.113.2 port 22 or for IPv6 Deny TCP any → 2001:db8:a::1 port 22. This blocks SSH from the internet without locking out the LAN. Replies to the router's own connections always pass.

Example: DMZ

#ActionProtocolSourceDestinationPort
1allowTCPany192.168.2.8080
2allowall192.168.1.0/24any
–deny(default)

From outside only the web server is reachable via HTTP, the LAN may go out.

Router(config)# firewall default deny
Router(config)# firewall rule 1 allow tcp any 192.168.2.80 port 80 in wan
Router# show firewall

In the simulation every rule counts its hits; the device console reports blocked packets.

How to do it in leyoNET

The same text as in the app’s help (F1 key).

Firewall

A firewall decides for every packet: let it through or drop it. It checks the rules from top to bottom; the first match wins. If none matches, the default rule applies. The safe choice is «deny everything not allowed» (default rule *Deny*).

A rule consists of:

  • action: Allow or Deny
  • protocol (TCP, UDP, ICMP or any) and for TCP/UDP the destination port, e.g. 80 for HTTP, 443 for HTTPS, 53 for DNS
  • source and destination: any, an address or a network such as 192.168.1.0/24
  • on a router optionally the inbound interface (where the packet arrives). Packets decrypted from a VPN (IPsec) tunnel have the inbound interface VPN tunnel (command line in vpn), not WAN – like the «IPsec» interface in pfSense or OPNsense

Stateful inspection: the firewall remembers allowed connections. Replies come back without a rule of their own. Turn it off and the return direction needs a rule too – this shows why stateful firewalls exist.

Routers filter forwarded packets (after DNAT, before SNAT), end devices filter incoming packets (host firewall). Packets to the router itself are only checked by a rule that explicitly names one of the router's addresses as destination, e.g. Deny TCP any → 203.0.113.2 port 22, inbound WAN blocks SSH from the internet (works the same for IPv6 addresses, e.g. 2001:db8:a::1); replies to its own connections always pass. Configure it in the Firewall tab of the advanced settings. In the simulation, counters show how often each rule matched; blocked packets appear in the console. A typical setup: a DMZ with the web server, only port 80/443 open from outside. See also NAT/PAT, VPN (IPsec) and Access lists (ACL).

Own device: the Firewall from the shop filters out of the box. Command line on router and firewall: firewall default deny, firewall rule allow tcp any 192.168.2.80 port 80 in eth0 (a number first inserts at that position), no firewall rule 2, no firewall stateful, show firewall. Switches use access lists instead: Access lists (ACL).

See an example

  • Demo “Firewall with DMZ” in leyoNETDemo “Firewall with DMZ” in leyoNET
    Firewall with DMZ

    A router with a firewall separates LAN, DMZ and Internet. From outside only the web server on port 80 is reachable.

    «Aussen» opens the web server (allowed), then pings the office PC (blocked, see the router's console). Filter «tcp.port == 80 or icmp».

    Watch live Project file

  • Demo “Firewall device and ACL” in leyoNETDemo “Firewall device and ACL” in leyoNET
    Firewall device and ACL

    A dedicated firewall separates WAN, LAN and DMZ; an access list on the switch port lets guests reach only the web server.

    «Aussen» opens the web server in the DMZ (allowed) and pings the office PC (firewall blocks). Then the guest notebook pings the office PC (ACL drops) and opens the web server (allowed). Filter «tcp.port == 80 or icmp».

    Watch live Project file

“Watch live” opens the network in leyoNET, the simulation runs in a loop. In the app you find it under File → Demo networks, with a step-by-step tour.

Practise

  • ★★★☆☆ Firewall: securing a DMZ · 4 goals · Worksheet (German)
  • ★★★★★ Final exercise: set up an office · 10 goals · Worksheet (German)

In leyoNET under Tools → Exercise catalogue. Every exercise checks itself.

What leyoNET simplifies

ProtocolLayerSimplification in the simulation
Firewall (packet filter)3Rules in order, the first match applies, otherwise the default rule; stateful over protocol, addresses and ports (timeout 5 minutes), related ICMP errors may return. Routers filter forwarded packets after DNAT and before SNAT, end devices incoming ones; broadcasts and DHCP replies are exempt

Read on

Found a mistake or have an idea? Source of this page on GitHub.