
In this article, we will walk you through the process of setting up and saving VLANs (Virtual Local Area Networks) on an Ethernet network card in Ubuntu. VLANs are a powerful tool for segmenting networks into smaller, more manageable parts.
To setup and save VLANs on Ethernet in Ubuntu, you need to install the vlan
package, load the 8021q
kernel module, create a new VLAN interface using the vconfig
command, assign an IP address to the VLAN interface using the ip
command, make the VLAN setup permanent by adding the 8021q
module to the kernel on boot, and configure the interface to be available during system boot by editing the /etc/network/interfaces
file.
Prerequisites
Before we start, ensure that you have administrative access to your Ubuntu system. You will need to execute some commands with superuser privileges.
Step 1: Install the VLAN Package
Firstly, we need to install the vlan
package. This package provides us with the necessary tools to create and manage VLANs in Ubuntu. You can install it by running the following command:
sudo apt-get install vlan
The sudo
command is used to execute the command with superuser privileges. apt-get install vlan
is the command that installs the vlan
package.
Step 2: Load the 8021q Kernel Module
After installing the vlan
package, we need to load the 8021q
kernel module. This module is responsible for VLAN tagging in the Linux kernel. Run the following command to load it:
sudo modprobe 8021q
The modprobe
command is used to add a module to the Linux kernel. In this case, we’re adding the 8021q
module.
Step 3: Create a New VLAN Interface
Now, we can create a new VLAN interface. We will use the vconfig
command for this. For example, to create a VLAN interface with ID 100 on eth0
, run:
sudo vconfig add eth0 100
Here, vconfig add eth0 100
is the command that adds a new VLAN with ID 100 to the eth0
interface.
Step 4: Assign an IP Address to the VLAN Interface
Once the VLAN interface is created, we need to assign an IP address to it. We can use the ip
command for this. For instance, to assign the IP address 10.0.0.1/24
to eth0.100
, run:
sudo ip addr add 10.0.0.1/24 dev eth0.100
The ip addr add
command is used to assign an IP address to a network interface. 10.0.0.1/24
is the IP address and subnet mask, and dev eth0.100
specifies the network interface.
Step 5: Make the VLAN Setup Permanent
To make the VLAN setup permanent, we need to add the 8021q
module to the kernel on boot. Run the following command to achieve this:
sudo bash -c 'echo "8021q" >> /etc/modules'
This command appends the string “8021q” to the /etc/modules
file. This file contains the names of kernel modules that should be loaded at boot time.
Step 6: Configure the Interface for System Boot
Next, we need to configure the interface to be available during system boot. Open the /etc/network/interfaces
file with a text editor and add the following lines:
auto eth0.100
iface eth0.100 inet dhcp
vlan-raw-device eth0
Here, auto eth0.100
ensures the interface is brought up at boot time. iface eth0.100 inet dhcp
configures the interface to use DHCP to obtain an IP address. vlan-raw-device eth0
specifies the physical device the VLAN interface is attached to.
Conclusion
By following these steps, you should now have a working VLAN setup on your Ubuntu system. Remember to replace eth0
and 100
with your network interface name and desired VLAN ID, respectively. For more information on VLANs and their usage, you can refer to the Ubuntu Server Guide.
Remember, the proper configuration and management of VLANs can greatly enhance the security and performance of your network. Always plan your network layout carefully and test your configurations thoroughly.
Yes, you can set up VLANs on any Ethernet network card in Ubuntu as long as it is supported by the Linux kernel.
Yes, you can have multiple VLANs on the same network interface. Each VLAN will have a unique VLAN ID.
Yes, you can assign multiple IP addresses to a VLAN interface. Simply use the ip addr add
command multiple times with different IP addresses.
You can check if the 8021q module is loaded by running the command lsmod | grep 8021q
. If the module is loaded, it will display the module name in the output.
To remove a VLAN interface, use the command sudo vconfig rem <interface>.<vlan_id>
. For example, sudo vconfig rem eth0.100
will remove the VLAN interface with ID 100 on the eth0
interface.