#!/bin/sh # IFACE1=eth0 IP1=201.57.53.2 GW1=201.57.53.1 LAN1=201.57.53.0/24 IFACE2=eth0 IP2=201.45.43.2 GW2=201.45.43.1 LAN2=201.45.43.0/24 routes_start() { ip rule add from ${IP1} table link1 ip route add 127.0.0.0/8 dev lo table link1 ip route add ${LAN1} dev ${IFACE1} src ${IP1} link1 ip route add default via ${GW1} dev ${IFACE_LINK1} table link1 ip rule add fwmark 1 table link1 prio 10 ip rule add from ${IP2} table link2 ip route add 127.0.0.0/8 dev lo table link2 ip route add ${LAN2} dev ${IFACE1} src ${IP2} link2 ip route add default via ${GW2} dev ${IFACE_LINK2} table link2 ip rule add fwmark 2 table link2 prio 20 ip route flush cache } routes_stop() { ip rule del from ${IP1} table link1 ip route del 127.0.0.0/8 dev lo table link1 ip route del ${LAN1} dev ${IFACE1} src ${IP1} link1 ip route del default via ${GW1} dev ${IFACE_LINK1} table link1 ip rule del fwmark 1 table link1 prio 10 ip rule del from ${IP2} table link2 ip route del 127.0.0.0/8 dev lo table link2 ip route del ${LAN2} dev ${IFACE2} src ${IP2} link2 ip route del default via ${GW2} dev ${IFACE_LINK2} table link2 ip rule del fwmark 2 table link1 prio 20 ip route flush cache } case "$1" in 'start') routes_start ;; 'stop') routes_stop ;; 'restart') routes_stop sleep 2 routes_start ;; *) echo "usage $0 start|stop|restart" esac