How to set up source based routing with Linux
This document (7008874) is provided subject to the disclaimer at the end of this document.
SUSE Linux Enterprise Server 15 Service Pack 3
SUSE Linux Enterprise Server 15 Service Pack 2
SUSE Linux Enterprise Server 15 Service Pack 1
SUSE Linux Enterprise Server 15
SUSE Linux Enterprise Server 12 Service Pack 5
SUSE Linux Enterprise Server 12 Service Pack 4
SUSE Linux Enterprise Server 12 Service Pack 3
SUSE Linux Enterprise Server 12
At the bottom, please type 100 SECONDPOA.
Replace SECONDPOA with any other string.
Save the file.
Please type ip rule add from s.s.s.s table SECONDPOA where s.s.s.s is the IP Address of the eth1.
Please type ip route add default via y.y.y.y dev eth1 table SECONDPOA and press Enter where y.y.y.y is the IP Address of the next hop for packets originating from eth1.
To test it, please type
traceroute www.suse.com -S p.p.p.p where p.p.p.p is the IP Address of eth0 and notice the next hop. This should be x.x.x.x
traceroute www.suse.com -S s.s.s.s where s.s.s.s is the IP Address of eth1 and notice the next hop. This should be y.y.y.y
Once the above test is successful, please follow the sub steps below to make ip rule statement persistent across reboot.
Create a file /etc/rc.d/rclocal .
Paste the following in the file. Modify the ip rule statement accordingly.
### BEGIN INIT INFO
# Provides: rclocal
# Required-Start: $local_fs $remote_fs $network
# X-UnitedLinux-Should-Start: $ALL
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Simulates rc.local
# Description: Simulates redhat's rc.local: contains
# commands to execute after system has booted (all services are already
### END INIT INFO
case "$1" in
ip rule add from s.s.s.s table SECONDPOA
Save the file
Type "chmod +x rclocal" without quotes and press Enter.
Type "chkconfig rclocal on" without quotes and press Enter.
Once the above test is successful, please make the ip route statement persistent. Please edit /etc/sysconfig/network/routes and type
default y.y.y.y - eth1 table SECONDPOA
where y.y.y.y is the next hop that packets originating from eth1 needs to take.
In Linux, by default, packets are considered individually for routing purposes. Thus, all the routing algorithm considers is where to send a packet based on that packet itself, without taking into consideration that the packet may be a response packet of sorts. In a typical setup, this means that all outgoing traffic is going out over one interface, eth0.
If multiple NICs in Linux are configured with addresses in the same subnet, by default communication into that subnet will always be done by the first NIC in that subnet that is started.
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:7008874
- Creation Date: 21-Jun-2011
- Modified Date:08-Nov-2022
- SUSE Linux Enterprise Server
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com