Advanced and Rare Routing Rules for Learning Engineers

Author: JJustis | Published: 2025-10-08 22:16:53
Advanced and Rare Routing Rules for Learning Engineers

1. Policy-Based Routing (PBR)
Route based on policies like source IP, DSCP, or application type instead of destination IP.
Use case: Send VoIP over low-latency links while backups go over cheaper links.
Example:
echo "200 voip" >> /etc/iproute2/rt_tables
ip rule add from 192.168.1.100 table voip
ip route add default via 10.0.0.2 dev eth0 table voip

2. Asymmetric Routing Handling
Mark packets to ensure return traffic takes the same path in multi-homed routers.
Example:
iptables -t mangle -A PREROUTING -s 192.168.1.0/24 -j MARK --set-mark 1
ip rule add fwmark 1 table 100
ip route add default via 10.1.1.1 dev eth1 table 100

3. Source-Based NAT (SNAT)
NAT based on source IP rather than outgoing interface.
Use case: Different departments have separate public IPs.
Example:
iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o eth0 -j SNAT --to-source 203.0.113.10
iptables -t nat -A POSTROUTING -s 192.168.20.0/24 -o eth0 -j SNAT --to-source 203.0.113.11

4. ECMP Routing with Advanced Metrics
Split traffic across multiple paths using weights or latency measurements.
Example:
ip route add default nexthop via 10.0.0.1 weight 2 nexthop via 10.0.0.2 weight 1

5. VRF (Virtual Routing and Forwarding)
Multiple isolated routing tables in one router.
Use case: Multi-tenant labs or experimental traffic isolation.
Example:
ip link add vrf-blue type vrf table 10
ip link set dev eth0 master vrf-blue
ip netns add blue_ns
ip link set dev eth0 netns blue_ns

6. Packet Marking & Routing by Port
Mark TCP/UDP packets and route them differently.
Example:
iptables -t mangle -A PREROUTING -p tcp --dport 80 -j MARK --set-mark 2
iptables -t mangle -A PREROUTING -p tcp --dport 443 -j MARK --set-mark 2
ip rule add fwmark 2 table vpn
ip route add default via 10.8.0.1 dev tun0 table vpn

7. Blackhole / Null Routing
Silently drop traffic by routing to a null interface.
Example:
ip route add blackhole 203.0.113.50/32

8. Multipath TCP / Intelligent Failover
Split flows across multiple links and failover dynamically.
Use case: Data center redundancy or resilient home lab setups.

9. BGP Route Reflection / Local Preference Tweaks
Adjust routing preference for traffic paths in lab BGP setups.
Example (pseudo Cisco):
route-map PREFER_LINK1 permit 10
set local-preference 200

10. Time-Based / Conditional Routing
Change routes dynamically based on time of day or system load.
Example:
# Daytime route
ip route add default via 10.0.0.1
# Nighttime backup
0 0 * * * ip route replace default via 10.0.1.1