Introduction to Split Gateways
8,425 Total views across this article’s versions; includes the historical baseline where available.
Having explained gateway routes, this article examines what the series calls a split gateway: routes or policies that send selected traffic through different paths.
It focuses on reading the configuration and reasoning about route selection. The Split Gateway Tutorial covers configuration examples. “Split gateway” here is descriptive terminology, not a special Linux route type or a way to bypass routing validation.
Gateway or Route?
A route is a table entry describing a destination prefix and how matching traffic should be handled. It can lead directly through an interface or via a next-hop router. A host route describes one address; it is not restricted to a physically attached host.
A gateway is the next-hop router used by a route. It may forward traffic toward private networks, the Internet, or another part of a tunnel topology. A route and a gateway are not alternative kinds of network object: a route can use a gateway.
Why Do We Need Gateways?
On a typical Ethernet LAN, directly connected destinations can be resolved on the link. Other destinations are reached through a router that is itself reachable. A virtual or point-to-point interface can provide a direct device route without a separate Ethernet next hop.
A default route is the least-specific destination prefix (0.0.0.0/0 for IPv4). It is used when that table has no more-specific usable match. It is not necessarily an Internet route, and a table can have more than one default route.
The “Work” in “Net-Work”
A router forwards a packet toward its destination using its own routing decision. Each hop needs a suitable path; the originating host does not need a complete list of every intermediate router.
Routing does not by itself imply address translation, application proxying, or permission to forward. Those are separate functions. A route also does not prove that the next hop or the complete end-to-end path is currently healthy.
Split Routes
Destination-based splitting uses different prefixes for different paths. Source-based or mark-based selection uses policy rules to choose a table, then uses the routes in that table. These are ordinary routing mechanisms.
One route can cover an entire prefix, while a more-specific route overrides it for a subset of destinations in the same table. Overlap is normal: a /24 connected route, a /1 VPN route, and a /0 default can all be valid together.
For symmetric replies across multiple uplinks, marking the incoming packet alone is insufficient. A reply is a different packet and does not automatically inherit that packet mark. A connection-mark design must save the chosen connection mark and restore it to the appropriate outgoing/reply packets before the relevant route selection. Locally generated replies generally use mangle/OUTPUT; forwarded reply traffic requires the corresponding received-packet path. NAT, source addresses, reverse-path filtering, and the return routes must also fit the design.
ip… Rules…
ip rule selects routing actions or tables according to selectors such as source address, incoming interface, or an existing packet mark. It does not set the mark or perform NAT. Packet marking and NAT belong to other parts of the networking stack, such as Netfilter.
Use destination routes when destination alone is the desired distinction. Use policy routing when another selector should change the table lookup. Multiple nexthops can support load distribution, but redundancy and end-to-end failover require a defined way to detect failure and change the usable paths. A collection of routes is not, by itself, a health-check system or a VPN kill switch.
Routing Tables Review
The usual initial IPv4 policy rules consult local (table 255), main (254), and default (253), in that order. The default table is normally empty; its name does not make it the only table that can contain a default route.
Tables contain routes; rules determine when to look in them. The kernel maintains local-address routes, while administrators commonly use main and custom tables for other policies. Emptying a table, removing a name alias, and deleting a policy rule are different operations. None should be confused with deleting a reserved table identifier.
More than one default route can exist in a table, and table IDs are not limited to 255. See Linux Routing Table Architecture and iproute and Routing Tables.
Split Gateways
A split can mean directing selected prefixes to different gateways, selecting different tables for different traffic, or replacing one broad destination route with several more-specific routes. State the intended criterion first; these designs have different behavior.
The examples below use destination-prefix selection. They do not implement source-based policy, balanced traffic volumes, automatic failover, or a complete privacy policy.
Splitting the Default Gateway
There is no one-default-route-per-table or one-gateway-per-interface limit. Different metrics can express preference among defaults, and an explicitly configured multipath route can have several nexthops.
Another technique retains a /0 default and adds 0.0.0.0/1 plus 128.0.0.0/1 through a VPN. Each /1 is more specific than /0. Together they cover the IPv4 address space, while more-specific local and tunnel-server routes can still take precedence. This is ordinary longest-prefix matching, not a trick to make invalid defaults acceptable.
It Takes Two (or More)
The two /1 ranges are:
| Prefix | Inclusive destination range |
|---|---|
| 0.0.0.0/1 | 0.0.0.0 through 127.255.255.255 |
| 128.0.0.0/1 | 128.0.0.0 through 255.255.255.255 |
These ranges do not overlap with each other. Both overlap the broader /0, which is expected and valid. The /1 routes are not themselves default routes. They can use the same VPN next hop; having two prefix rows does not imply two VPN servers or an equal division of traffic volume.
Benefits of Split Default Gateways
The two-/1 method can redirect ordinary IPv4 destinations through a VPN while retaining the original /0 route. OpenVPN documents it as the def1 option of redirect-gateway.
That is broad VPN redirection, not selective split tunneling merely because two prefixes appear. For a selective tunnel, route the intended destinations or select a policy table for the intended traffic.
The VPN server’s transport address needs a route outside the tunnel so the tunnel can carry its own encrypted traffic without a routing loop. If the /1 routes disappear and the physical /0 remains, traffic can fall back outside the tunnel unless filtering prevents it. IPv6 and DNS behavior must be designed separately.
Single (“Main”) Routing Table Solutions
In one table, a lookup chooses among that table’s routes using destination specificity and other relevant attributes such as metric. The printed row order is not a firewall-style first-match policy.
main is the usual general-purpose table, but it is not the only table an administrator can configure. A single-table design works when destination prefixes describe the desired split. It does not become source- or connection-aware merely because several gateways appear.
Multiple Routing Tables
Policy rules are processed by priority. A matching rule may look up a specified table. If that lookup yields a usable route, lookup normally stops; if there is no route, processing can continue to a later rule. A throw route also permits continuation, while rejecting route types can terminate with an error.
An earlier successful default route can therefore prevent a later table from being consulted. The kernel does not compare every route in every table and choose a global longest prefix. Use explicit selectors and priorities to express which traffic should use which table. This behavior is described in ip-rule(8).
Examples
These are illustrative IPv4 routing-table excerpts, not commands to install and not captures from a working VPN. They omit the host’s local table and policy rules. Assume the displayed connected subnets and tunnel next hops are configured and reachable as described.
Examples 2–4 assume a point-to-point tun0 with reachable peer 10.8.0.1; an explicit peer route is shown. The physical path uses eth0 on 10.10.0.0/24 with router 10.10.0.1. The illustrative VPN server transport address is 198.51.100.20, reached through that physical router.
Example #1: Single Routing Table, Dual NICs, Dual Gateways
Two default routes with different metrics are a valid configuration:
10.10.0.0/24 dev eth1 scope link
192.168.15.0/24 dev eth2 scope link
default via 10.10.0.1 dev eth1 metric 100
default via 192.168.15.1 dev eth2 metric 200
For otherwise comparable lookups without a more-specific match, the metric-100 route is preferred. This does not automatically send replies back through the interface on which a request arrived. It also does not prove that the metric-200 route will take over whenever the Internet beyond the first router fails. For those goals, add the appropriate policy and failure-detection design; do not infer them from row order.
Example #2: Single Routing Table, Split Gateway, Default to VPN
Here both halves of IPv4 use one VPN peer, while the physical default remains:
10.10.0.0/24 dev eth0 scope link
10.8.0.1 dev tun0 scope link
198.51.100.20 via 10.10.0.1 dev eth0
0.0.0.0/1 via 10.8.0.1 dev tun0
128.0.0.0/1 via 10.8.0.1 dev tun0
default via 10.10.0.1 dev eth0 metric 100
Destinations in either /1 ordinarily use tun0, but 10.10.0.0/24 stays on the LAN and the /32 route to 198.51.100.20 keeps the VPN transport outside the tunnel. The /32 peer route reaches the tunnel next hop. The lower half ends at 127.255.255.255; 128.0.0.0 begins the upper half.
There is one retained /0 plus two more-specific /1 routes. Both /1 routes use the same peer. This excerpt does not split traffic between two VPN providers.
Example #3: Single Routing Table, Split Gateway, Multiple LANs
Add a second connected LAN on eth1:
10.10.0.0/24 dev eth0 scope link
192.168.15.0/24 dev eth1 scope link
10.8.0.1 dev tun0 scope link
198.51.100.20 via 10.10.0.1 dev eth0
0.0.0.0/1 via 10.8.0.1 dev tun0
128.0.0.0/1 via 10.8.0.1 dev tun0
default via 10.10.0.1 dev eth0 metric 100
Each /24 is more specific than the relevant /1, so destinations on both connected LANs use their LAN interfaces. The rest of ordinary IPv4 traffic uses the tunnel except where another more-specific route applies. The first LAN is consistently 10.10.0.0/24; it is not 10.10.10.0/24 under another display mode.
Example #4: Single Routing Table, Split Default Gateway (Partial VPN)
This deliberately coarse destination split sends the lower half through the VPN and leaves the broader physical default for other destinations:
10.10.0.0/24 dev eth0 scope link
10.8.0.1 dev tun0 scope link
198.51.100.20 via 10.10.0.1 dev eth0
0.0.0.0/1 via 10.8.0.1 dev tun0
default via 10.10.0.1 dev eth0 metric 100
0.0.0.0/1 covers 0.0.0.0–127.255.255.255; destinations from 128.0.0.0 upward use /0 when no more-specific route applies. The prefixes overlap, and the more-specific match intentionally wins. The LAN and peer routes remain exceptions. This divides address space, not necessarily traffic volume, and it does not distinguish applications.
On a host configured like the excerpt, these read-only lookups help inspect the selected paths:
ip -4 route get 10.10.0.50
ip -4 route get 100.64.0.1
ip -4 route get 203.0.113.20
ip -4 route get 198.51.100.20
Expected paths under the stated assumptions are LAN, tunnel, physical default, and explicit VPN-transport route respectively. These commands perform routing lookups; they do not send traffic or establish that the tunnel is healthy.
Primary references: ip-route(8), ip-rule(8), and the OpenVPN 2.6 manual's redirect-gateway/def1 description. For packet-versus-connection marks, see the reviewed MARK and CONNMARK reference.