Routing and Filtering Network Traffic

Topics · Published 2019-07-17 · Revised 2026-11-23
Reviewed corrections applied locally; pre-review version preserved separately · Joomla source

4,559 Total views across this article’s versions; includes the historical baseline where available.

A brief, high-level introduction to Linux routing and packet filtering: what the kernel decides, and which tools configure those decisions.

10,000 Foot View

Routing selects how a packet reaches its destination. Packet filtering decides whether a packet is allowed to proceed. Packet modification, including NAT and marking, is another function that can interact with those decisions. These functions work together, but they are not interchangeable layers of one command.

When I began researching Linux firewall architecture for a Virtual Private Network (VPN) application, I was stunned by how difficult it was to find answers to basic, high level questions. While I found an abundance of low-level troubleshooting and configuration information, I needed to begin my analysis from a higher viewpoint. Ultimately, I ended up writing a guide on Linux networking simply because I didn’t want to repeat the process in the future. Good documentation seemed like the best way to ensure that was the case.

Oh Packet, Wherefore Art Thou?

For an incoming IPv4 packet, Linux must determine whether it belongs to a local address or needs forwarding. For a locally generated packet, Linux must select a route toward the destination. Policy rules can influence which routing table is consulted; a lookup within that table normally selects the longest matching destination prefix.

Filtering applies at stages of those paths. A packet can have a valid route and still be dropped by a firewall. Conversely, accepting a packet does not create a route or enable IP forwarding.

There is no universal promise that a Linux installation permits all traffic. The effective behavior depends on the installed rules, their policies, the services listening, and system settings. Ubuntu’s UFW is initially disabled in its standard setup, but that fact does not establish the complete policy of a particular host. IPv4 forwarding is a separate setting.

Tool or facilityRole
Linux routing subsystemSelects routes, handles local delivery and forwarding, and uses routing policy rules.
ip routeInspects and changes kernel routing tables; it is part of iproute2.
ip ruleInspects and changes the routing policy database. It selects routing actions/tables rather than rewriting packets.
NetfilterKernel facilities for packet processing at hooks, including filtering, connection tracking, and NAT.
iptables / nftUserspace commands for configuring packet-processing rules. iptables may use a legacy or nftables backend.
UFWA firewall-management frontend that generates lower-level rules; it is not an independent replacement for the kernel networking stack.

ip route is not an application layer on top of Netfilter. Routing and Netfilter interact in the packet path, which is why the placement of a mark or address change can affect a later routing decision.

For a VPN, begin by deciding which destinations or sources should use the tunnel. Destination routes may be enough for a simple split. More selective routing may need policy rules and separate tables; a fail-closed policy also needs filtering that covers the intended packet paths. IPv6 and DNS need their own consideration.

The primary command references are ip-route(8), ip-rule(8), and iptables(8). See Ubuntu's firewall documentation for UFW, and the Linux Firewall Management Tools Overview for the packet paths.