In ubuntu 18.04 or later, we have an application called netplan to manage our network. The configuration file is located in
/etc/netplan directory. In this tutorial, We will using netplan to configure trunk vlan interface.
Before start we make sure that we will have no permission issue on the configuration process.
To demonstrate how we can make our interface a trunk vlan, we will use this use case:
__________________ |______ | vlan 110 -----------\ | | | |-------|eth0 | ubuntu | vlan 120 -----------/ |______| server | |__________________|
Our server will have 1 interface named
eth0 that connected to 2 vlans.
- On vlan
110we will assign
192.168.6.60/24ip address with gateway to
- On vlan
120we will assign
To configure the network in our server, first open the configuration file:
In my server the file name is
50-cloud-init.yaml, maybe it is different in your case. Just open the yaml file located on
This is how the configuration is implemented to suits the use case we mention above:
network: ethernets: eth0: dhcp4: false vlans: vlan.110: id: 110 link: eth0 addresses: [192.168.6.60/24] gateway4: 192.168.6.1 vlan.120: id: 120 link: eth0 addresses: [172.16.100.99/24] version: 2
As we can see here, to define vlan interface we need
vlans: directive. If you need more vlan interface, just add another vlan configuration under
vlans: directive. The key to binding the vlan to the interface is
link: eth0 on each vlan configuration, make sure the interface name is right. When we define the link, it will treat the link as trunk vlan.
You can check your interface name by running this command:
After editing the file, use this command to activate the new configuration:
Thats it! Congratulation you just made a vlan interface on your Ubuntu 18.04!