+1-323-999-6135 blog@hegars.com

https://www.thomas-krenn.com/en/wiki/Two_Default_Gateways_on_One_System

Add new route table

/etc/iproute2/rt_tables
+ 1 rt2

Add the routes and rules to the route table

ip route add 1.2.3.0/24 dev ens7 src 1.2.3.4 table rt2
ip route add default via 1.2.3.254 dev ens7 table rt2
ip rule add from 1.2.3.4/32 table rt2
ip rule add to 1.2.3.4/32 table rt2

Check it out

ip route list table rt2
ip rule show

Add startup script

/etc/network/interface
to interface
post-up ip route add 1.2.3.0/24 dev ens7 src 1.2.3.4 table rt2
post-up ip route add default via 1.2.3.254 dev ens7 table rt2
post-up ip rule add from 1.2.3.4/32 table rt2
post-up ip rule add to 1.2.3.4/32 table rt2

https://wiki.linuxfoundation.org/networking/iproute2_examples

Traceroute with interface and source

root@debtest:~# traceroute -i ens7 -s 10.0.0.3 192.168.1.150
traceroute to 192.168.1.150 (192.168.1.150), 30 hops max, 60 byte packets
1 10.0.0.10 (10.0.0.10) 1.348 ms 1.327 ms 1.300 ms
2 172.18.8.253 (172.18.8.253) 13.621 ms 13.641 ms 13.638 ms
3 172.18.1.2 (172.18.1.2) 25.842 ms 25.744 ms 25.798 ms
4 192.168.1.150 (192.168.1.150) 30.148 ms 30.147 ms 30.131 ms

Ping from source IP

root@debtest:~# ping -I 10.99.0.3 192.168.1.150
PING 192.168.1.150 (192.168.1.150) from 10.99.0.3 : 56(84) bytes of data.
64 bytes from 192.168.1.150: icmp_seq=1 ttl=125 time=34.7 ms
64 bytes from 192.168.1.150: icmp_seq=2 ttl=125 time=28.3 ms
64 bytes from 192.168.1.150: icmp_seq=3 ttl=125 time=24.0 ms
64 bytes from 192.168.1.150: icmp_seq=4 ttl=125 time=22.8 ms
^C
— 192.168.1.150 ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 22.820/27.502/34.745/4.663 ms