Routes in Netplan... using routes: from the example says unknown key

I have two NIC both connected to private networks one that goes to a dead end network and the other that can get to the internet through NAT.

When I bring up both the defaut route gets switched to the network that goes nowhere and none of the networking works anymore.

I've tried

routes:
 - to: 0.0.0.0/0
 via: <gateway address>
 metric: 1

from the freaking man page and netplan generate return unknown key routes

Got to love it when the documentation is evidently wrong.

Anyone know how I tell netplan which nic to use for the internet? Set a default route?

Very frustrating.

thanks.

EDIT: Okay... appears I've figured it out. Routes are associated with the interfaces rather than being global. As in...

ethernets:
  enp0:
    name: enp0s3
    addresses: [192.168.0.128/24]
    gateway4: 192.168.0.1
    nameservers:
      addresses: [8.8.8.8,8.8.4.4]
    routes:
     - to: <network>
     via: <gateway address>
     metric: 1
  enp1:
   <etc...>
    routes:
     - to: <network>
     via: <gateway address>
     metric: 5

At least generate doesn't throw errors and the routes apper to change.


Solution 1:

As you stated in your question, the netplan man page is wrong. In the example in the man page routes are incorrectly placed on the same level as ethernets:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    id0:
      match:
        macaddress: 00:11:22:33:44:55
      wakeonlan: true
      dhcp4: true
      addresses:
      - 192.168.14.2/24
      ...
  routes:
  - to: 0.0.0.0/0
    via: 11.0.0.1
    metric: 3

The correct way is to place the routes under the interface that the routes go via, for example:

network:
  ...
  ethernets:
    id0:
      addresses:
      - 10.0.0.2/24
      ...
      routes:
      - to: 192.168.0.0/16
        via: 10.0.0.1

Solution 2:

[SOLUTION} Sort of...

The netplan routing I put in the question is correct and works. My problem turns out to be with Virtualbox's networking being unstable. It will work fine a one point and then will fail for no apparent reason on the next re-boot.

Time to try VMPlayer.