Cannot add extra ip addresses on Ubuntu 20.04. using netplan

My servers has 10.20.10.100 ip address on eno1 interface.

I can successfully add temporarily ip address 10.20.50.60 (or any else).

When I try to add permanently using netplan I cannot connect to server anymore using it original ip address.

Content of my original /etc/netplan/00-installer-config.yaml:

network:
  ethernets:
    eno1:
      dhcp4: true
    eno2:
      dhcp4: true
    enx7e8ae1d2cba7:
      dhcp4: true
  version: 2

My changed version is:

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: false
      addresses:
        - 10.20.10.100/24
        - 10.20.50.60/24
        - 10.20.50.61/24
      gateway4: 10.20.0.1
      nameservers:
          addresses: [10.20.0.1,1.1.1.1,8.8.8.8]
    eno2:
      dhcp4: true
    enx7e8ae1d2cba7:
      dhcp4: true

ip address show dev eno1

2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 7c:8a:e1:d2:cb:a2 brd ff:ff:ff:ff:ff:ff
    inet 10.20.10.100/16 brd 10.20.255.255 scope global dynamic eno1
       valid_lft 438sec preferred_lft 438sec

route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.20.0.1       0.0.0.0         UG    100    0        0 eno1
10.20.0.0       0.0.0.0         255.255.0.0     U     0      0        0 eno1
10.20.0.1       0.0.0.0         255.255.255.255 UH    100    0        0 eno1
169.254.95.0    0.0.0.0         255.255.255.0   U     0      0        0 enx7e8ae1d2cba7
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.18.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker_gwbridge

My changed version is (version2):

network:
version: 2
ethernets:
    eno1: {}
    eno2:
        dhcp4: true
    enx7e8ae1d2cba7:
        dhcp4: true
vlans:
    vlan.101:
        id: 101
        link: eno1
        addresses: [10.20.10.100/16]
        gateway4: 10.20.0.1
        nameservers:
            addresses: [10.20.0.1, 1.1.1.1]
    vlan.102:
        id: 102
        link: eno1
        addresses: [10.20.50.60/16]
        gateway4: 10.20.0.1
        nameservers:
            addresses: [10.20.0.1, 1.1.1.1]
    vlan.103:
        id: 103
        link: eno1
        addresses: [10.20.50.61/16]
        gateway4: 10.20.0.1
        nameservers:
            addresses: [10.20.0.1, 1.1.1.1]

Solution 1:

There appears to be nothing wrong with the configuration you specified so it makes me think about how you applied the change.

Secondly, the output of ip address show dev eno1 showed an address of 10.20.10.100/16 instead of the /24 in your netplan config. Feels like the previous interface details were cached or new ones not applied.

To help determine your address details when using DHCP, run the following commands and make note of the output:

# All IP addresses
ip a

# Routes and default gateway
ip r

Now change netplan config and disable DHCP by setting it to false. Having changed the netplan config, apply with debug flag to help determine any issues:

sudo netplan --debug apply

Then repeat the commands above and note the differences. Sometimes a reboot is necessary to remove existing interfaces or you can use the ip del command to remove existing IP addresses before applying new netplan config.

One way to convince yourself the new config was applied is to change the /16 to something different e.g. /22. If the output of ip a is the same as before then it hasn't applied properly.

Solution 2:

I would configure you addresses as virtual lans (As an aside, I think you may need set gateways for the vlans on different network segments):

network:
    version: 2
    ethernets:
        eno1: {}
        eno2:
            dhcp4: true
        enx7e8ae1d2cba7:
            dhcp4: true

    vlans:
        vlan.101:
            id: 101
            link: eno1
            addresses: [10.20.10.100/16]
            routes:
            - to: default
              via: 10.20.0.1
        vlan.102:
            id: 102
            link: eno1
            routes:
            addresses: [10.20.50.60/16]
            routes:
            - to: default
              via: 10.20.0.1
        vlan.103:
            id: 103
            link: eno1
            addresses: [10.20.50.61/16]
            routes:
            - to: default
              via: 10.20.0.1