Post

Vlans In Ubuntu 2404 With Virtualbox

Welcome to this comprehensive guide on setting up VLANs (Virtual Local Area Networks) within an Ubuntu 24.04 environment using VirtualBox as our virtualization platform. This article is tailored towards experienced.

# Vlans In Ubuntu 2404 With VirtualBox: Self-Hosted Networking for Your Homelab

Welcome to this comprehensive guide on setting up VLANs (Virtual Local Area Networks) within an Ubuntu 24.04 environment using VirtualBox as our virtualization platform. This article is tailored towards experienced sysadmins and DevOps engineers seeking practical solutions for their self-hosted infrastructure needs, focusing on automation and open-source technologies.

Prerequisites

Ensure you have the following prerequisites installed:

  1. Ubuntu 24.04: We’ll be using this as our base operating system for the VLAN host machine.

  2. VirtualBox (6.x): The latest version of Oracle VirtualBox is recommended for optimal performance and compatibility.

  3. Vagrant (2.x): This open-source tool will help us manage our virtual machines easily.

  4. Docker (20.10.x): Docker is essential for containerizing our network services, making them portable and easy to scale.

  5. Debian 11 (Buster): Our guest OS of choice for VLAN-enabled virtual machines.

Solution Breakdown

Step 1: Install VirtualBox and Vagrant

1
2
3
4
5
# Update your system packages list
sudo apt update

# Install VirtualBox and Vagrant
sudo apt install virtualbox vagrant

Step 2: Create a Vagrantfile

Create a new directory for your project, navigate into it, and create a Vagrantfile. We’ll configure our environment here.

1
2
3
mkdir my_vlan_project
cd my_vlan_project
nano Vagrantfile

Step 3: Configure the Vagrantfile

Configure your Vagrantfile as shown below:

1
2
3
4
5
6
7
8
9
10
11
Vagrant.configure("2") do |config|
  config.vm.box = "debian/buster64" # Debian Buster 64-bit box

  config.vm.network "private_network", type: "dhcp"
  config.vm.network "custom_network", ip: "192.168.50.10", netmask: "255.255.255.0" # Set your VLAN IP here
  config.vm.network "nic1", type: "vlan", id: "10" # Set your VLAN ID here

  config.vm.provider "virtualbox" do |vb|
    vb.memory = "512"
  end
end

Step 4: Initialize and Up the Vagrant Machine

Now, navigate back to your project root directory and initialize your Vagrant environment. Then, start the virtual machine.

1
2
3
cd ~/my_vlan_project
vagrant init
vagrant up

Step 5: Install Docker on the Guest OS

Once the guest OS is booted, SSH into it and install Docker:

1
2
3
4
5
6
7
8
9
# Update your system packages list
sudo apt update

# Install Docker
sudo apt install docker.io -y

# Start and enable Docker service
sudo systemctl start docker
sudo systemctl enable docker

Step 6: Configure VLAN Interface with Docker Networking

Create a new network namespace, bridge, and VLAN interface using the following commands in your guest OS. Replace 10 with your desired VLAN ID:

1
2
3
4
5
6
7
8
9
10
11
# Create a new network namespace
sudo ip netns add vlan10

# Create a new bridge interface connected to the VLAN namespace
sudo ip link add name br-vlan10 type bridge vlanid 10 master ens3

# Assign IP address and netmask for the VLAN interface
sudo ip addr add 192.168.50.11/24 dev br-vlan10

# Set up the bridge to automatically bring up when the system starts
sudo systemctl enable br-vlan10

Step 7: Deploy Network Services in Docker Containers

Create a new Dockerfile for your desired network service, build the container image, and run it. This process may vary depending on the specific service you’re deploying.

Troubleshooting

In case of issues, check the following:

  • Ensure that VirtualBox supports VLANs in your current version.
  • Make sure the VLAN IP address is unique within the subnet.
  • Double-check all the configuration files for syntax errors and typos.

Conclusion

By following this guide, you’ve successfully set up a VLAN in Ubuntu 24.04 using VirtualBox. This self-hosted networking solution can help improve your infrastructure’s flexibility, scalability, and security—key aspects of any DevOps workflow. Don’t forget to document and optimize your configurations for future reference!

Happy automating! 🚀💻✨

This post is licensed under CC BY 4.0 by the author.