Via Cà Matta 2 - Peschiera Borromeo (MI)
+39 02 00704272
info@synaptica.info

Ubuntu 20.04 manage routing of multiple gateways and interfaces from a single VM

Digital solution partner

Ubuntu 20.04 manage routing of multiple gateways and interfaces from a single VM

 

 

With the advent of netplan it is possible to manage the routing for each network interface in a simple way.

For example, if we have a VM connected to two separate LANs with two network cards and obviously two gateways we have to manage the routing of packets, because Linux is known to route everything to the default gateway.

To overcome this problem, it is sufficient to modify the netplan configuration.

Let’s see how to do it with a few simple steps:

  1. have iproute2 installed

2. modify the “sudo nano / etc / iproute2 / rt_tables” file by inserting the last two lines with numbers that define the priorities

insert as last two lines:

3) modify the conf. of netplan for interfaces:

Each interface has a settings block in this file. At the end of this block, we will add policy settings and routing rules for the interface.

We configure the first network interface which has the following parameters (let’s say it is connected with lan1):

  • name: enp0s5
  • ip address: 10.10.0.20
  • network: 10.10.0.0/24
  • gateway: 10.10.0.1
  • macaddress: 54: 45: 42: 51: 12: 09

Configuriamo la seconda interfaccia di rete che ha i seguenti parametri (diciamo che è connessa con la lan2):

  • nome: enp1s6
  • ip address: 192.168.10.30
  • network: 192.168.10.0/24
  • gateway: 192.168.10.1
  • macaddress: 56:55:46:51:12:09

( per ottenere il mac address delle interfacce è sufficiente eseguire “ifconfig -a” )

 

 

The same operation must be performed for all interfaces connected to the various LANs of your infrastructure. Obviously if you have more than two you will need to add more lines to the rt_tables file.