Linux – /etc/interfaces file for multiple gateways, same network? (linux)

interfaceiplinuxnetworkingrouting

I've got my ip routing table setup as I'd like it:

# ip r s
10.1.248.0/24 dev eth0  proto kernel  scope link  src 10.1.248.11 
default via 10.1.248.1 dev eth0  metric 100 
default via 10.1.248.3 dev eth0  metric 200 

10.1.248.1 is the primary gateway, and 10.1.248.3 is the backup gateway. Is there a way to configure /etc/network/interfaces to create this setup upon boot?

Best Answer

Sure, something like this may work

auto eth0
iface eth0 inet static
    address 10.1.248.11
    netmask 255.255.255.0
    up ip route add default via 10.1.248.1 dev eth0  metric 100 
    up ip route add default via 10.1.248.3 dev eth0  metric 200