1

My Debian server has 2 NICs with 2 VLANs:

  • Nic1 = vlan10 = 192.168.10.5 (static)
  • Nic2 = vlan20 = 192.168.20.5 (static)

/etc/network/interface:

auto ens192
iface ens192 inet static
    address 192.168.10.5
    netmask 255.255.255.0
    gateway 192.168.10.1
    dns-nameservers 127.0.0.1 1.1.1.1 8.8.8.8

auto ens224
iface ens224 inet static
    address 192.168.20.5
    netmask 255.255.255.0
    gateway 192.168.20.1
    dns-nameservers 127.0.0.1 1.1.1.1 8.8.8.8

I imagine that if I set nic1 gateway 192.168.10.1, nic2 gateway 192.168.20.1, the traffic to 192.168.10.0/24 will route to nic1, and the same with nic2

But then I got the error, Googled it and found out I can't have 2 gateway in the /etc/network/interface. To achieve what I want, I need to configure static route.

I belive I learned in school that routing table is generated from /etc/network/interface. So my question is: why I'm not allowed to use 2 gateways?

6
  • Unfortunately, questions about hosts/servers/VMs are off-topic here. You could try to ask this question on Super User.
    – Ron Maupin
    Commented Jun 4 at 18:52
  • Just ask yourself: If you have more than one, which is the default of the defaults? Commented Jun 4 at 19:31
  • You can, but "ifup" doesn't know how to handle this. The last "gateway" processed will be the one in the route table. In general, it only makes sense to have one default gateway. If you want load balancing / sharing, equal-cost-multi-path (ECMP) is one way to do it, but not a very good one. (Modern linux doesn't have a route cache, so there's no stickiness as to which path is followed.)
    – Ricky
    Commented Jun 4 at 21:05
  • seems to me that this is a network engineering valid question... indeed sometimes I use more than 1 gateway configured in the same host but different nics...
    – ZEE
    Commented Jun 4 at 22:41
  • The correct way is to use a unique default gateway -tied to the "primary" interface- and use specific routes for the traffic that should go through the other interface.
    – JFL
    Commented Jun 5 at 10:32

0

Browse other questions tagged or ask your own question.