2

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.

3
  • 2
    Please do not post the answer to your problem in the question. Instead you can post the answer here below and mark it as 'solved'. – THelper Dec 20 '17 at 9:01
  • Indeed. Post it as an answer so the searchers can find it and benefit from it. – chili555 Dec 20 '17 at 14:50
  • Please see: askubuntu.com/questions/1034518/… – wwk May 4 at 13:37
5

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
0
1

[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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.