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?

4 Answers 4

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.

2
  • 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: pocketnix.org/posts/…
    – Andi Jay
    Commented Feb 2, 2018 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.
    Commented Feb 11, 2018 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!

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.

3
  • Unfortunately this adds VLAN tags to IP packets. And, as I need to simply connect other computers to the network to, VLAN is not an option.
    – Maciek D.
    Commented Jan 14, 2018 at 9:31
  • 1
    Do you mind pointing to the bug report? I've just discovered the very same problem. Commented Feb 15, 2018 at 15:56
  • 3
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .