1

I'm using fresh Ubuntu Server 18.10 (Cosmic) installation with netplan. What I'm trying to achieve is to setup network interface via DHCP and add some static routes.

With static IP settings things are working correctly. With DHCP 'routes:' are not applied

Any ideas how to change that?

Commands used to apply settings:

netplan generate
netplan apply

WORKS

network:
 ethernets:

  enp0s3:
   addresses: []
   dhcp4: true
   dhcp6: true

  enp0s8:
   dhcp4: false
   addresses:
     - 192.168.1.10/24
   routes:
    - to: 10.10.0.0/24
      via: 192.168.1.2
    - to: 10.9.0.0/24
      via: 192.168.1.2
 version: 2

DOES NOT WORK

network:
 ethernets:

  enp0s3:
   addresses: []
   dhcp4: true
   dhcp6: true

  enp0s8:
   dhcp4: true           # <- CHANGED
   addresses: []         # <- CHANGED
   routes:
    - to: 10.10.0.0/24
      via: 192.168.1.2
    - to: 10.9.0.0/24
      via: 192.168.1.2
 version: 2

EDIT: [20.12.2018]: After new research I was able to find that my issue is an animal (a bug to be specific).

  • Should this addresses: [] be there? – George Udosen Dec 19 '18 at 19:12
  • I have tried with this line removed as well, no change. – felixd Dec 19 '18 at 19:13
  • Please run it with sudo netplan --debug apply and post the specific errors! – George Udosen Dec 19 '18 at 19:16
  • Nothing interesting. Just, same, configuration but formatted differently + not informations not related with subject. (I can't paste log here, it's just too long). – felixd Dec 19 '18 at 19:24
  • After new research I was able to find that my issue is an animal (a bug to be specific). * bugs.launchpad.net/netplan/+bug/1781652 * github.com/systemd/systemd/issues/1850 – felixd Dec 20 '18 at 11:30
1

After new research I was able to find that my issue is an animal (a bug to be specific).

Routes are applied before DHCP, which destroys them.

0

Try this... (keep the indentation and spacing as it is)...

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: true
      dhcp6: true
      addresses: []
    enp0s8:
      dhcp4: true
      addresses: []
      routes:
        - to: 10.10.0.0/24
          via: 192.168.1.2
        - to: 10.9.0.0/24
          via: 192.168.1.2

Then...

sudo netplan --debug generate # generate config files

sudo netplan apply # apply configuration

reboot # reboot and confirm proper operation

Update #1:

Because of the bugs that you found, try this...

Name the only existing .yaml file as 01-dhcp.yaml and include this text...

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: true
      dhcp6: true
      addresses: []
    enp0s8:
      dhcp4: true
      addresses: []
      gateway4: 10.x.x.1 <-adjust this address for your environment
      optional: true     <-don't wait for connection, try with/without this

Then create a second .yaml file called 02-routes.yaml with this text...

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s8:
      dhcp4: false   <-disable dhcp this time around
      addresses: []  <-this MAY need to be removed
      routes:
        - to: 10.10.0.0/24
          via: 192.168.1.2
        - to: 10.9.0.0/24
          via: 192.168.1.2

sudo netplan --debug generate # generate config files

sudo netplan apply # apply configuration

reboot # reboot and confirm proper operation

  • FYI, it's not just the indentation but also the spacing between elements as well. (Even if you keep indentation lined up extra line spaces will mess with it) – Thomas Ward Dec 20 '18 at 1:33
  • After new research I was able to find that my issue is an animal (a bug to be specific). * bugs.launchpad.net/netplan/+bug/1781652 * github.com/systemd/systemd/issues/1850 – felixd Dec 20 '18 at 11:11
  • @felixd see Update #1 in my answer. It may require slight tweaking, but the idea is to set routes AFTER the dhcp has hopefully completed. Report backk to "@heynnema" – heynnema Dec 20 '18 at 14:56
  • @heynnema this does not work...configs from different files are merged (repeated fields are overwritten) – felixd Dec 20 '18 at 19:03
  • @felixd then I guess that you're stuck with assigning a static address. – heynnema Dec 20 '18 at 19:06

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.