Skip to content

Instantly share code, notes, and snippets.

@hoangdh
Last active June 12, 2023 20:45
Show Gist options
  • Save hoangdh/d076b9bb14a1a7b3b457660505a550ce to your computer and use it in GitHub Desktop.
Save hoangdh/d076b9bb14a1a7b3b457660505a550ce to your computer and use it in GitHub Desktop.
Adding sub-interface and IP Addresses using NetPlan on Ubuntu 18.04

Adding sub-interface and IP Addresses using NetPlan on Ubuntu 18.04

Edit /etc/netplan/*.yml

network:
  version: 2
  # renderer: NetworkManager
  ethernets:
    eth0:
      addresses: 
        - 192.168.100.116/24
        - 192.168.100.117/24
        - 192.168.100.118/24
      gateway4: 192.168.100.1
      nameservers:
          search: [google.com]
          addresses: [8.8.8.8, 8.8.4.4]
     eth0:1:
      addresses: 172.16.1.69/32

Apply this config

netplan apply
@hoodadt
Copy link

hoodadt commented Sep 29, 2022

didn't work for me :(
i am using ubuntu 22.04.1 LTS can't apply this configuration

@kinire98
Copy link

If I didn't understand it in a wrong way, you create a subinterface (eth0:1) when you want to add an address that is in another subnet. If it's in the same subnet you just add the new address in the same interface

@hoodadt
Copy link

hoodadt commented Apr 6, 2023

no i am configuring openstack neturon module this module need an individual interface without any ip address or gateway assigned to it
it uses this network port for flat network communications
that's why
and this eth0:1 stuff works in some distros but not in ubuntu
i was able to create them but you have to add vlan tag ;(
i am looking for way to create them withouth any vlan tags since i am running labrator with no access to switchs

@LowLatencyMatters
Copy link

LowLatencyMatters commented Jun 12, 2023

Basically the sub interface is the same interface, but having the VLAN tag.
'eth0:1' is not a sub interface, but interface alias.

you can use aliases with 22.04 in this way:

            addresses:
            - 172.31.40.227/32:
                label: "rest1:1"

If you just need separate virtual interface, you can use dummy interface, it will use your default route table, have no VLAN, but MAC & IP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment