Operations 7 min read

How to Add Custom Policy Routing for Multiple NICs on Linux

This guide explains how to configure additional routing rules for a second network interface on Linux by creating a new policy routing table, adding specific routes and rules with iproute2 commands, and verifying that traffic uses the intended NIC.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Add Custom Policy Routing for Multiple NICs on Linux

By default Linux routes all traffic through the primary interface (eth0). When a server has a second NIC (eth1) with its own IP address and gateway, you must add extra routes so that traffic to and from that subnet uses eth1.

In the example, eth0 is configured with IP 19.86.101.54/24 and gateway 19.86.101.1, while eth1 uses IP 19.86.100.176/24 and gateway 19.86.100.1. The ifconfig -a output shows both interfaces, and netstat -rn confirms the default route points to eth0.

To direct traffic through eth1, create a new policy routing table. First back up the existing table file, then add an entry named admin:

cd /etc/iproute2
cp rt_tables rt_tables.orig
echo "1 admin" >> /etc/iproute2/rt_tables

Next, add routes to the admin table for the eth1 subnet and its default gateway:

ip route add 19.86.100.0/24 dev eth1 src 19.86.100.176 table admin
ip route add default via 19.86.100.1 dev eth1 table admin

Then create rules so that any traffic originating from or destined to the eth1 IP range uses the admin table:

ip rule add from 19.86.100.176/24 table admin
ip rule add to 19.86.100.176/24 table admin
ip route flush cache

After applying these commands, ip rule show should list the new entries (e.g., 32764 and 32765) above the default main lookup, ensuring the rules are evaluated first.

Verify the configuration by pinging the eth1 address from an external network; the traffic should now flow through eth1. To make the changes persistent across reboots, add the commands to /etc/init.d/boot.local on SUSE or /etc/rc.d/rc.local on Red Hat/CentOS. Repeat the steps with a different table name if you need additional sub‑net configurations.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxNetwork ConfigurationnetstatPolicy Routingifconfigiproute2
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.