Unix & Linux: Adding two default gateways in Debian interfaces file
Channel: Roel Van de Paar
Date: 2020-08-19

Unix & Linux: Adding two default gateways in Debian interfaces file


The Question: This is my interfaces file:
auto eth0
iface eth0 inet static
 address 192.168.1.10
 netmask 255.255.255.0
 gateway 192.168.1.1

auto eth1
iface eth1 inet static
 address 192.168.2.10
 netmask 255.255.255.0
 gateway 192.168.2.1
If I restart networking daemon I get this error: eth1 is not up. I want two
default gateways https://superuser.com/questions/341030/i-have-both-cable-and-
dsl-at-home-how-do-i-put-that-to-good-use. This is how my routing table should
be:
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth1
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth1
I got the above table by using ifconfig and route add default gw commands. But
I want to do it with the /etc/network/interfaces file. How can I do it?
Update1:
iface eth0 inet static
 address 192.168.1.10
 netmask 255.255.255.0
 up ip route del 192.168.1.0/24
 post-up ip route add 192.168.1.0/24 dev eth0 metric 1
 up route add default gw 192.168.1.1 metric 1

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user nixnotwin (https://unix.stackexchange.com/users/2926), user Eli Rosencruft (https://unix.stackexchange.com/users/17186), and the Stack Exchange Network (http://unix.stackexchange.com/questions/35713). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.