having trouble getting my head around netplan.

I have 2 interfaces: ens18 & 19. ens18 is connected to my external network, ens19 connected internally. I want all internet bound traffic to go out via ens18, however, it always goes out via ens19.

I set the DHCP metric on ens19 to 200, hoping that would resolve it, but no luck.

Here's my 50-cloud-init.yaml

network:
    ethernets:
        ens18:
            addresses: []
            dhcp4: true
        ens19:
            addresses: []
            dhcp4: true
            routes:
             - to: 10.0.0.0/24
               via: 10.100.0.254
               metric: 100
               table: 101
             - to: 10.0.1.0/24
               via: 10.100.0.254
               metric: 100
               table: 101
            routing-policy:
             - from: 10.0.0.0/24
               table: 101
             - from: 10.0.1.0/24
               table: 101
    version: 2

My 10-netplan-ens18.network

[Match]
Name=ens18

[Network]
DHCP=ipv4

[DHCP]
UseMTU=true
RouteMetric=100

And my 10-netplan-ens19.network

[Match]
Name=ens19

[Network]
DHCP=ipv4

[Route]
Destination=10.0.0.0/24
Gateway=10.100.0.254
Metric=100
Table=101

[Route]
Destination=10.0.1.0/24
Gateway=10.100.0.254
Metric=100
Table=101

[RoutingPolicyRule]
From=10.0.0.0/24
Table=101

[RoutingPolicyRule]
From=10.0.1.0/24
Table=101

[DHCP]
UseMTU=true
RouteMetric=200

You'll notice that I added some static routes on ens19. This is because, when I copied the intial ens19 config file to /etc/systemd/network (without the static routes) the internet-bound traffic did go out via ens18, but I wasn't able to connect to the ens19 interface from my internal network (my laptop is on a different subnet to the server)

My ip route output is

default via 10.100.0.254 dev ens19 proto dhcp src 10.100.0.13 metric 100
default via 10.1.2.254 dev ens18 proto dhcp src 10.1.2.3 metric 100
10.1.2.0/24 dev ens18 proto kernel scope link src 10.1.2.3
10.1.2.254 dev ens18 proto dhcp scope link src 10.1.2.3 metric 100
10.100.0.0/24 dev ens19 proto kernel scope link src 10.100.0.13
10.100.0.254 dev ens19 proto dhcp scope link src 10.100.0.13 metric 100

And ip rule is

0:      from all lookup local
0:      from 10.0.0.0/24 lookup 101
0:      from 10.0.1.0/24 lookup 101
32766:  from all lookup main
32767:  from all lookup default

TL;DR I have an 18.04 server with 2 NICs, both assigned an address via DHCP (I'd rather keep it that way) but am unable to define both the default route to 0.0.0.0/0 and access the second interface from my internal network.

Hope someone can help here. I found it much easier to do this with 16.04 and previous.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.