19

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?

Maciek D.
  • 431
  • 1
  • 3
  • 9

4 Answers4

13

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.

Maciek D.
  • 431
  • 1
  • 3
  • 9
  • I guess you'd have to setup a macvlan or ipvlan to get yourself a virtual interface with it's own distinct name, ip, and mac. There isn't good information on how to do this, but you can start here: http://www.pocketnix.org/posts/Linux%20Networking:%20MAC%20VLANs%20and%20Virtual%20Ethernets – Andi Jay Feb 02 '18 at 16:21
  • @AndiJay, the problem is not hot to do this (this can be easily done with an `ip` command, but how to to this with the netplan. However, it seems that simply netplan does not have such functionality. I have already filled a bug report. – Maciek D. Feb 11 '18 at 16:37
9

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!

Michael
  • 190
  • 1
  • 7
3

With the version of Netplan in 22.04 (Jammy), you can use labelling on an additional address to achieve the concept of virtual interface:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp7s0f0:
      addresses:
          - aaa.aaa.aaa.aaa
          - bbb.bbb.bbb.bbb:
              label: enp7s0f0:0
      routes:
          - to: default
            via: aaa.aaa.aaa.1

Andrew
  • 595
  • 3
  • 7
3

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.