NetPlan Not Applying Static IP for VLAN – Fix

ubuntu-18.04vlan

I setup a new Ubuntu 18.04 server and spend some time fighting with netplan. I only need a very simple network config, but for some reason it does not work and I have no idea what is wrong.

I need a VLAN with a static IP.

The problem: As soon as I configure any static IP (either on the physical interface or the VLAN) I loose any connection.

This is my current (not working) yaml (it is the only yaml, so there is no other config interfering)

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0: #the physical interface
    match:
      macaddress: "xx:xx:xx"
    dhcp4: no

    #this is the same IP I would get with dhcp
    addresses: [ "10.1.0.1/24" ]
    gateway4: 10.1.0.254
vlans:
  lab1:
    id: 10
    link: eth0
    dhcp4: no
    addresses: [ "10.1.10.100/24" ]

After applying the config I got following IF<->IP:
eth0 <-> 10.1.0.1
lab1 <-> 10.1.0.1

And I was unable to connect to the server via ssh or ping it at this IP.

Configuration after running netplan generate:

10-netplan-eth0.network

[Match]
MACAddress=xx:xx:xx

[Network]
Address=10.1.0.1/24
Gateway=10.1.0.254
VLAN=lab1

10-netplan-lab1.network

[Match]
Name=lab1

[Network]
Address=10.1.10.100/24

10-netplan-lab1.netdev

[NetDev]
Name=lab1
Kind=vlan

[VLAN]
Id=10

If I change both to dhcp4: yes and remove the addresses/gateway, I get the same addresses as statically configured above from DHCP and ssh/ping work for the VLAN address.

If I change eth0 to dhcp4: yes and leave the static config for lab1, lab1 gets a DHCP assigned address.

Why is the static address for lab1 ignored?

Note: I was assured the switching/routing is correctly configured, but I am willing to check this again.

Best Answer

Since this question may get other views, I thought I'd quickly answer.

The syntax of the YAML file must be correct in order for the items to be configured. Check the file with "netplan --debug generate" to see issues, else the generate and apply will configure whatever is valid, and ignore the rest (to be resilient - something is better than nothing).

In this case, the OP's indentation of the vlan section is incorrect. It must line up with the "ethernets" heading, indented from the "network" heading. Should be:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0: #the physical interface
    match:
      macaddress: "xx:xx:xx"
    dhcp4: no

    #this is the same IP I would get with dhcp
    addresses: [ "10.1.0.1/24" ]
    gateway4: 10.1.0.254
  vlans:
    lab1:
      id: 10
      link: eth0
      dhcp4: no
      addresses: [ "10.1.10.100/24" ]
Related Topic