Several workloads share a physical server. Each application is bound to a different source address, yet requests still leave through the same interface. The problem is usually not address binding, but routing policy: Linux first matches policy rules, then looks up the corresponding routing table. This guide builds a dual-link lab in two network namespaces to verify source addresses, outbound interfaces, and return paths without changing the host’s default route.
Understand the three routing decisions
The source address determines “which local address to use,” the routing table determines “how to reach the destination,” and ip rule determines “which table to consult for this lookup.” None can replace the others. Even after an application binds to an address, its traffic may still use the main routing table if no matching policy rule exists.
Adding a public IP address does not automatically add a gateway or a physical uplink. A production network may use the same interface, routed address delivery, or another method of providing addresses. Confirm the actual gateway, prefix, and conditions for using the addresses before proceeding. Do not copy this lab topology directly onto a public network.
The addresses in this guide are for an isolated lab only; they are not MmuCloud provisioning parameters. Service addresses and credentials are available in the console after payment. Base any real network configuration on the provisioning details and confirmation through a support ticket.
The test has a single goal: traffic to the same destination must use link A when sent from source address A, use link B when sent from source address B, and receive the correct replies. NAT is not enabled, and forwarding throughput is not tested.
Build an isolated topology
Use Debian 12 with iproute2, iputils-ping, and procps installed. Run the following commands in a Bash shell with administrative privileges. First, check that the spr-src and spr-peer namespaces do not already exist. If either exists, stop and choose another pair of names rather than deleting an unfamiliar environment.
The two veth pairs act as two virtual network cables. spr-src represents the application host, while spr-peer represents a peer reachable over both links. The destination address resides on the peer’s loopback interface, so IP forwarding is not required.
ip netns add spr-src
ip netns add spr-peer
ip link add spa type veth peer name ppa
ip link add spb type veth peer name ppb
ip link set spa netns spr-src
ip link set spb netns spr-src
ip link set ppa netns spr-peer
ip link set ppb netns spr-peer
ip -n spr-src addr add 192.0.2.2/30 dev spa
ip -n spr-peer addr add 192.0.2.1/30 dev ppa
ip -n spr-src addr add 198.51.100.2/30 dev spb
ip -n spr-peer addr add 198.51.100.1/30 dev ppb
ip -n spr-peer addr add 198.18.0.9/32 dev lo
ip -n spr-src link set lo up
ip -n spr-peer link set lo up
ip -n spr-src link set spa up
ip -n spr-src link set spb up
ip -n spr-peer link set ppa up
ip -n spr-peer link set ppb up
To keep reverse-path filtering from interfering with the initial test, disable IPv4 rp_filter only inside these two namespaces. Set both all and the individual interfaces; do not assume that changing just one is sufficient.
for ns in spr-src spr-peer; do
for dev in all default lo; do
ip netns exec "$ns" sysctl -qw \
"net.ipv4.conf.$dev.rp_filter=0"
done
done
for dev in spa spb; do
ip netns exec spr-src sysctl -qw \
"net.ipv4.conf.$dev.rp_filter=0"
done
for dev in ppa ppb; do
ip netns exec spr-peer sysctl -qw \
"net.ipv4.conf.$dev.rp_filter=0"
done
First, ping each directly connected peer address. If either direct connection fails, check interface states and addresses before adding any policy rules. Otherwise, a basic link failure could be mistaken for a routing policy problem.
Configure rules and routing tables
Start by adding only the default route for link A to the main table. Route lookups for both source addresses will use spa. This establishes a counterexample: different source addresses do not necessarily mean different outbound interfaces.
ip -n spr-src route add default via 192.0.2.1 dev spa
ip -n spr-src route get 198.18.0.9 from 192.0.2.2
ip -n spr-src route get 198.18.0.9 from 198.51.100.2
Next, create tables 101 and 102. In each table, add the directly connected subnet containing the gateway before adding the default route. This ensures that the default route has a reachable next hop. These table numbers are simply a convention for this lab, not system-reserved identifiers.
ip -n spr-src route add table 101 \
192.0.2.0/30 dev spa src 192.0.2.2
ip -n spr-src route add table 101 \
default via 192.0.2.1 dev spa
ip -n spr-src route add table 102 \
198.51.100.0/30 dev spb src 198.51.100.2
ip -n spr-src route add table 102 \
default via 198.51.100.1 dev spb
ip -n spr-src rule add priority 100 \
from 192.0.2.2/32 lookup 101
ip -n spr-src rule add priority 110 \
from 198.51.100.2/32 lookup 102
ip -n spr-src rule show
ip -n spr-src route show table 101
ip -n spr-src route show table 102
Rules with lower numeric priorities are evaluated first. Keep the system’s existing rule for the local table; do not flush the ruleset to “remove interference.” The source-address rules use /32 to restrict each match to a single address and avoid accidentally matching an entire subnet.
Verify outbound interfaces and return paths
Repeat the lookups. Source A should now show dev spa and table 101; source B should show dev spb and table 102. Do not judge the result from the default route list alone: each lookup must include the actual source address.
ip -n spr-src route get 198.18.0.9 from 192.0.2.2
ip -n spr-src route get 198.18.0.9 from 198.51.100.2
ip netns exec spr-src ping -c 3 -W 1 \
-I 192.0.2.2 198.18.0.9
ip netns exec spr-src ping -c 3 -W 1 \
-I 198.51.100.2 198.18.0.9
ip -n spr-peer route get 192.0.2.2 from 198.18.0.9
ip -n spr-peer route get 198.51.100.2 from 198.18.0.9
The peer’s return paths should use ppa and ppb, respectively. This lab relies on directly connected routes for replies. In production, you must confirm that the upstream network has the correct return routes. Correct routing in one direction does not guarantee that the remote endpoint can send a response back.
Next, remove the rule for B as a negative test. A lookup using source address B should fall back to the main table and use spa. Once the rule is restored, it should use spb again. Ping may continue to succeed throughout, so “it responds” is no substitute for checking the outbound interface.
ip -n spr-src rule del priority 110 \
from 198.51.100.2/32 lookup 102
ip -n spr-src route get 198.18.0.9 from 198.51.100.2
ip -n spr-src rule add priority 110 \
from 198.51.100.2/32 lookup 102
ip -n spr-src route get 198.18.0.9 from 198.51.100.2
If the lookups are correct but communication fails, check in order: packets leaving the local host, packets arriving at the peer, the peer’s return path, and filtering on the local host. Strict reverse-path validation requires the incoming interface to match the best reverse path; with asymmetric routing, it may drop legitimate packets. Do not copy the lab’s disabled filtering settings directly into production configuration.
Define the scope of production changes
Before applying this approach to a real configuration, identify which traffic needs source-based routing. If management, backup, or local application networks have dedicated paths, add those routes to the corresponding tables rather than sending everything through each table’s default route.
Check that applications actually bind to the expected addresses. For an application that does not bind explicitly, the kernel may select a source address based on another route, so the intended rule will not match. Forwarded traffic also requires separate checks of forwarding settings, firewall rules, and marking rules; those conditions are outside the scope of this lab.
Temporary ip commands are not persistent configuration. Manage production changes through the network management tool already in use, and avoid adding duplicate rules at startup. Keep the original configuration and a way to recover access. Check route lookups first, then make real application requests, and finally verify the state after reloading the configuration.
Once the lab is complete, confirm that no processes remain in the namespaces, then delete the two namespaces created for this test. Their associated veth interfaces will be removed as well, while the host’s default route remains unchanged.
ip netns pids spr-src
ip netns pids spr-peer
ip netns del spr-src
ip netns del spr-peer
Save the rule list, both routing tables, the lookups with explicit source addresses, and the return-path results. A valid test should explain why traffic takes a particular path and demonstrate how that behavior changes when a rule is removed.
Frequently asked questions
Does binding a source address also select the outgoing interface?
No. Binding selects a local address, while routing policy still determines the outgoing path. Query ip route get with that source and confirm the result with actual traffic.
Is a default route sufficient in a policy routing table?
Usually not. Include the connected route to the gateway and explicit routes for management or private networks that must not use the default path.
Should rp_filter be disabled in production?
Not by default. Inspect both all and interface settings, establish whether routing is asymmetric, and choose a mode that preserves the required anti-spoofing controls. Disabling it here is limited to the lab.
EPYC 7543P Dedicated Server
From $459.9/month