U2 Networking

Firewalls and routing for the homelab

The firewall is the one device in your lab that faces the internet all day, every day. Choose one you understand, give it its own hardware, write rules you can explain, and keep it patched.

At a glance

  • Run the firewall on its own small, dedicated device so that hypervisor maintenance never takes the household offline.
  • The best firewall is the one you understand. An accidental allow-all rule is a bigger risk than any missing feature.
  • Block inbound by default, allow outbound by default, and add specific rules between internal networks.
  • Keep it patched. Edge devices are attacked within hours of a vulnerability becoming public.
  • Export the configuration after every change and store a copy off the device.

What the firewall does

In a homelab the firewall is usually also the router. It sits between your provider's equipment and everything else, and it typically handles:

  • Routing between your internal networks and the internet.
  • Stateful filtering, which tracks connections so that replies to traffic you started are allowed back in automatically.
  • Network address translation, so many internal devices share one public address.
  • DHCP and DNS for each internal network.
  • VPN endpoints for remote access and site-to-site links.
  • Optional extras such as DNS filtering, intrusion detection and traffic reporting.

Give it dedicated hardware

Virtualizing the firewall is an excellent way to learn. Depending on it is a different matter. When the firewall runs on your hypervisor, every host reboot, storage problem or failed update takes the house offline, and you lose access to the documentation and downloads you need to fix it. A small fanless x86 box with two to six network ports draws roughly 8 to 25 W and removes that whole class of problem.

A useful way to decide is to rank everything in the lab by what happens when it goes down. A game server offline for an evening is an annoyance; the firewall offline means nobody in the house has internet, including you while you try to fix it. The most important device gets the simplest, most independent hardware.

If you do run a firewall as a virtual machine, pass the physical WAN network card through to it rather than bridging it, keep a known-good snapshot, and have a plan for getting online when the host is down.

Sizing the hardware

Routing and filtering a home connection needs very little CPU. Several things change that: very fast internet plans, VPN encryption at high speeds, intrusion detection rules and traffic inspection. Two cautions apply when reading performance claims:

  • Single-stream speed tests flatter firewalls. Real household traffic is thousands of small flows, and that pattern, plus any inspection rules, is what consumes CPU.
  • Network card quality matters. Server-grade network chipsets with mature drivers are far more dependable in BSD and Linux firewall distributions than the cheapest consumer chipsets.

For a multi-gigabit internet plan, choose hardware with 2.5 GbE or 10 GbE ports and check published throughput figures for the features you will actually enable.

Choosing a platform

Platform typeStrengthsTrade-offs
Open-source firewall distribution on an x86 applianceMature features, VPN options, policy routing, plugins for DNS filtering and intrusion detection, large documentation baseMore to learn; the interface assumes you know networking concepts
Integrated prosumer gateway from a switch and access point ecosystemOne dashboard for firewall, switching and wireless; easy VLANsAdvanced routing, VPN and reporting features are often limited; features vary by model
Command-line router operating systemExcellent for automation and for learning networking properlySteep learning curve; no friendly interface
Consumer router with stock firmwareSimple and cheapFew features, unclear update support, often abandoned after a few years

Look past feature checklists. A feature that exists on a datasheet but is awkward or unreliable in practice is not a feature you have. Buy on what the product does today, not on what a roadmap promises. Weigh how the vendor handles security reports: fast acknowledgement, clear advisories and quick patches matter more than a spotless history, because no product has one.

Rule of thumb

Pick the platform whose documentation you can follow and whose rules you can explain line by line. Switching firewall platforms later means rebuilding your whole network, so choose deliberately and then stick with it long enough to learn it well.

Connecting to your provider

  • Avoid double NAT. If your provider's equipment also routes, put it in bridge or passthrough mode so your firewall receives the public address. Double NAT breaks VPNs, gaming and port forwarding in subtle ways.
  • Check for carrier-grade NAT. If the WAN address on your firewall falls in 100.64.0.0/10, or differs from the address websites report for you, your provider is sharing public addresses between customers. Inbound connections will not reach you. Mesh overlays and outbound tunnels solve this; see Remote Access and VPNs.
  • Change one piece at a time. When replacing the provider's gateway, keep the old path working until the new one has carried the household's traffic for a few days. See owning your internet edge.
  • Plan for IPv6. If your provider offers it, your firewall needs rules for it too. A firewall that filters IPv4 carefully while IPv6 is wide open is a common oversight.

Writing rules that make sense

Firewall rules are evaluated in order, and on most platforms the first matching rule wins. Rules are usually applied on the interface where traffic enters the firewall. Keep these habits:

  1. Deny inbound from the internet by default. Every port forward is a decision you should be able to justify. Disable automatic port opening features such as UPnP unless a specific device needs them and you accept the risk.
  2. Allow outbound by default. Blocking all outbound traffic at home breaks updates, time sync and countless small things. Filter outbound selectively, for example on untrusted networks.
  3. Specify destinations, not source ports. Client source ports are random. Leave the source port as any and restrict the destination address and port.
  4. Use aliases. Group addresses and ports into named aliases such as "admin workstations" or "web ports" so rules read like sentences.
  5. Describe every rule. A one-line description explaining why a rule exists will save you an hour in six months.
  6. Remove temporary rules. The allow rule you added to test something on a Saturday is the one that causes the incident.
  7. Test from the other side. Confirm rules from a device on the network being restricted, not from your admin workstation.

Rules between internal networks are where segmentation really happens. Our VLANs and Segmentation guide includes a complete example rule set.

Filtering and detection

DNS filtering

Blocking known advertising, tracking and malware domains at the DNS level is cheap and effective for the whole network. Blocking newly registered domains catches a large share of phishing and malware infrastructure with few false positives. Expect DNS filtering to be bypassed by devices that use their own encrypted DNS; firewall rules that block outbound DNS to anything but your resolver help with that.

Geographic blocking

If you expose any service, blocking inbound connections from regions where you have no users reduces noise considerably. It is not a security boundary by itself, but it cuts down on automated scanning.

Intrusion detection and prevention

Intrusion detection is a valuable learning tool and a useful signal. It also produces false positives and consumes CPU. Start in alert-only mode, read every alert, tune the rules, and only then consider blocking. Remember that inspection sees little inside encrypted traffic.

TLS inspection

Inspecting encrypted web traffic requires installing your own certificate authority on every device and intercepting connections. It breaks applications, it is a privacy intrusion on the people in your house, and modern protocols make it harder every year. We do not recommend it for home networks.

Updates and configuration backups

Internet-facing appliances are among the most attacked devices on any network, and the time between a public vulnerability disclosure and active exploitation is often measured in hours. Treat firewall updates as a priority:

  • Read release notes before updating, especially for major versions.
  • Export the configuration before every update and after every change, and store copies on another machine and in your backups.
  • Use boot environments or snapshots where the platform supports them, so a bad update can be rolled back.
  • Schedule updates for a time when an outage will not disrupt the household, and keep a serial cable handy.
  • Never expose the firewall's management interface to the internet. Reach it from a trusted network or over a VPN.

From the Bench

Restoring an exported configuration file onto a fresh install of the same platform has taken us between 15 and 30 minutes every time we have practiced it. Rebuilding the same firewall from memory once took most of a weekend. Practice the restore before you need it.