Virtual interface in netplan

In the old /etc/network/interfaces I could define a virtual interface:

auto enp7s0f0
iface enp7s0f0 inet static
    address aaa.aaa.aaa.aaa
    netmask 255.255.255.0
    gateway aaa.aaa.aaa.1

auto enp7s0f0:0
iface enp7s0f0:0 inet static
     address bbb.bbb.bbb.bbb
     netmask 255.255.255.0

How this can be achieved with netplan on Ubuntu Server 17.10?

Right now I have:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp7s0f0:
      addresses: [aaa.aaa.aaa.aaa/24]
      gateway4: aaa.aaa.aaa.1

How to add virtual interface with the address bbb.bbb.bbb.bbb?


After some investigation, I found out that the current netplan does not suport it. It is possible to do:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp7s0f0:
      addresses: [aaa.aaa.aaa.aaa/24, bbb.bbb.bbb/24]
      gateway4: aaa.aaa.aaa.1

ip addr shows both adresses and the computer can communicate with the bbb.bbb.bbb/24 network. The downside is that there is a single interface name for both networks, which can be a problem while defining the iptables rules.


Just go back to ifupdown. It's super easy

apt install ifupdown

delete/rename any .yaml file in /etc/netplan - the important part is to be sure the file extension is not yaml

Done!


Try something like that:

network:
    version: 2
    renderer: networkd
    ethernets:
        enp7s0f0:
            addresses: [aaa.aaa.aaa.aaa/24]
            gateway4: aaa.aaa.aaa.1
    vlans:
        veth0:
            id: 0
            link: enp7s0f0
            addresses: [bbb.bbb.bbb.bbb/24]

I don't know if you need to define the gateway again for the virtual interface. Add it if it doesn't work.