Netplan with 2 NICs each connected to a different gateway
network:
version: 2
renderer: networkd
ethernets:
ens3:
addresses:
- 192.168.2.2/24
dhcp4: no
routes:
- to: 192.168.2.0/24
via: 192.168.2.1
table: 101
routing-policy:
- from: 192.168.2.0/24
table: 101
ens5:
addresses:
- 192.168.22.2/24
dhcp4: no
gateway4: 192.168.22.1
routes:
- to: 192.168.22.0/24
via: 192.168.22.1
table: 102
routing-policy:
- from: 192.168.22.0/24
table: 102
Source routing
Route tables can be added to particular interfaces to allow routing between two networks:
In the example below, ens3
is on the 192.168.2.0/24
network and ens5
is on the 192.168.22.0/24
network. This enables clients on either network to connect to the other and allow the response to come from the correct interface.
Furthermore, the default route is still assigned to ens5
allowing any other traffic to go through it.
Unfortunaly this is the most close way to use two gateways independent that I found I tried to add gateway4
on ens
3 and the firewall detect spoofing because for some reason the netplan will return the traffic the wrong way. tomorrow i'm going to rollback netplan to ifupdown in order to work with routing tables, etc. is more flexible.
Reference here
Related videos on Youtube
Biggen
Updated on September 18, 2022Comments
-
Biggen almost 2 years
Anyone familiar enough with Netplan?
I'm a bit confused on how to configure an Ubuntu 18 server with two NICS using Netplan. Each NIC is on a separate subnet. They are directly connected to separate router interfaces on the router (this is a SMB router so each interface is configured as a different subnet).
So for example on the server I have two NICs named below with the appropriate information they need:
eth0 - 192.168.2.2/24 gateway - 192.168.2.1 dns - 192.168.2.1
eth1 - 192.168.22.2/24 gateway - 192.168.22.1 dns - 192.168.22.1
I was playing around with the source routing example at netplan.io, but its not quite what I want. I don't want to route all outgoing traffic through just one interface. I need to be able to route traffic out of eth0 through eth0's gateway and I need to be able to route traffic out of eth1 through eth1's gateway.
I'll let the router handle routing between the two subnets via firewall rules. I just need Neplan to play nice with my two NICs and let me setup two subnets each with its own gateway information. Any ideas?