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
@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