Configure network bonding and VLAN tagging for high availability and network segmentation

Intermediate 45 min Apr 03, 2026 34 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Set up network bonding for link aggregation and failover protection while implementing VLAN tagging for network segmentation. This tutorial covers bond configuration with Netplan and NetworkManager across multiple interfaces.

Prerequisites

  • Root or sudo access
  • Two or more network interfaces
  • Basic understanding of networking concepts
  • Switch with VLAN/trunking support

What this solves

Network bonding (link aggregation) combines multiple network interfaces into a single logical bond interface, providing increased bandwidth and redundancy. VLAN tagging allows you to segment network traffic across the same physical infrastructure, improving security and organization. This configuration is essential for production servers requiring high availability and network isolation.

Understanding network bonding modes

Linux supports several bonding modes, each optimized for different use cases. The most common modes are:

ModeNameDescriptionUse Case
0balance-rrRound-robin load balancingMaximum throughput, requires switch support
1active-backupOne active, others standbyFailover protection, works with any switch
2balance-xorXOR hash load balancingLoad balancing with fault tolerance
4802.3adIEEE 802.3ad LACPStandards-based aggregation, requires LACP
5balance-tlbTransmit load balancingOutbound load balancing without switch config
6balance-albAdaptive load balancingBidirectional load balancing without switch config

Step-by-step configuration

Install bonding kernel module

Load the bonding module and ensure it loads on boot. This module provides the bonding functionality in the Linux kernel.

sudo modprobe bonding
echo 'bonding' | sudo tee -a /etc/modules

Identify network interfaces

List available network interfaces to determine which ones you want to bond together. You'll need at least two physical interfaces for bonding.

ip link show
lshw -class network -short

Configure bonding with Netplan (Ubuntu/Debian)

Create a Netplan configuration for network bonding with VLAN tagging. This example uses active-backup mode for failover protection.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: no
      dhcp6: no
    enp2s0:
      dhcp4: no
      dhcp6: no
  bonds:
    bond0:
      interfaces:
        - enp1s0
        - enp2s0
      parameters:
        mode: active-backup
        primary: enp1s0
        mii-monitor-interval: 100
        fail-over-mac-policy: active
      dhcp4: no
      dhcp6: no
  vlans:
    bond0.100:
      id: 100
      link: bond0
      addresses:
        - 192.168.100.10/24
      routes:
        - to: 0.0.0.0/0
          via: 192.168.100.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
    bond0.200:
      id: 200
      link: bond0
      addresses:
        - 192.168.200.10/24

Configure bonding with NetworkManager (RHEL-based)

Use NetworkManager commands to create bond and VLAN interfaces on AlmaLinux, Rocky Linux, and Fedora systems.

# Create the bond interface
sudo nmcli connection add type bond ifname bond0 con-name bond0 bond.options "mode=active-backup,miimon=100,primary=enp1s0"

Add slave interfaces to the bond

sudo nmcli connection add type ethernet ifname enp1s0 con-name bond0-slave1 master bond0 sudo nmcli connection add type ethernet ifname enp2s0 con-name bond0-slave2 master bond0

Create VLAN interfaces on the bond

sudo nmcli connection add type vlan ifname bond0.100 con-name vlan100 dev bond0 vlan.id 100 ip4 192.168.100.10/24 gw4 192.168.100.1 sudo nmcli connection add type vlan ifname bond0.200 con-name vlan200 dev bond0 vlan.id 200 ip4 192.168.200.10/24

Apply network configuration

Apply the network configuration and restart networking services to activate the bonding and VLAN setup.

sudo netplan apply
# Bring up the connections
sudo nmcli connection up bond0
sudo nmcli connection up bond0-slave1
sudo nmcli connection up bond0-slave2
sudo nmcli connection up vlan100
sudo nmcli connection up vlan200

Configure advanced bonding mode (802.3ad LACP)

For maximum performance with switch support, configure 802.3ad LACP mode. This requires LACP configuration on your switch.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: no
      dhcp6: no
    enp2s0:
      dhcp4: no
      dhcp6: no
  bonds:
    bond0:
      interfaces:
        - enp1s0
        - enp2s0
      parameters:
        mode: 802.3ad
        lacp-rate: fast
        mii-monitor-interval: 100
        transmit-hash-policy: layer3+4
      dhcp4: no
      dhcp6: no
# Delete existing bond and recreate with LACP
sudo nmcli connection delete bond0
sudo nmcli connection add type bond ifname bond0 con-name bond0 bond.options "mode=802.3ad,lacp_rate=1,miimon=100,xmit_hash_policy=layer3+4"

Configure trunk interface for multiple VLANs

Set up a trunk interface to carry multiple VLAN tags across the bonded connection. This allows you to segment traffic effectively.

# Create additional VLAN interfaces
sudo ip link add link bond0 name bond0.300 type vlan id 300
sudo ip link add link bond0 name bond0.400 type vlan id 400

Assign IP addresses to VLAN interfaces

sudo ip addr add 192.168.300.10/24 dev bond0.300 sudo ip addr add 192.168.400.10/24 dev bond0.400

Bring interfaces up

sudo ip link set bond0.300 up sudo ip link set bond0.400 up

Set up bond monitoring script

Create a monitoring script to track bond status and automatically handle failover events.

#!/bin/bash

Bond monitoring script

BOND_INTERFACE="bond0" LOG_FILE="/var/log/bond-monitor.log" log_message() { echo "$(date): $1" >> $LOG_FILE } check_bond_status() { if [ -f "/proc/net/bonding/$BOND_INTERFACE" ]; then ACTIVE_SLAVE=$(grep "Currently Active Slave" /proc/net/bonding/$BOND_INTERFACE | awk '{print $4}') BOND_STATUS=$(grep "Bonding Mode" /proc/net/bonding/$BOND_INTERFACE) log_message "Bond Status: $BOND_STATUS" log_message "Active Slave: $ACTIVE_SLAVE" # Check for any down slaves grep -A 1 "Slave Interface" /proc/net/bonding/$BOND_INTERFACE | grep -B 1 "MII Status: down" | grep "Slave Interface" | while read line; do FAILED_SLAVE=$(echo $line | awk '{print $3}') log_message "WARNING: Slave interface $FAILED_SLAVE is down" done else log_message "ERROR: Bond interface $BOND_INTERFACE not found" fi } check_bond_status
sudo chmod 755 /usr/local/bin/bond-monitor.sh

Create systemd timer for bond monitoring

Set up automated monitoring using systemd timers to regularly check bond status and log any issues.

[Unit]
Description=Bond Interface Monitor
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/bond-monitor.sh
User=root
StandardOutput=journal
StandardError=journal
[Unit]
Description=Run bond monitor every 5 minutes
Requires=bond-monitor.service

[Timer]
OnCalendar=*:0/5
Persistent=true

[Install]
WantedBy=timers.target
sudo systemctl daemon-reload
sudo systemctl enable --now bond-monitor.timer

Test failover scenarios

Verify that your bonding configuration properly handles interface failures and maintains connectivity.

Simulate interface failure

Test failover by bringing down the primary interface and monitoring bond behavior.

# Check current active slave
cat /proc/net/bonding/bond0 | grep "Currently Active Slave"

Bring down primary interface

sudo ip link set enp1s0 down

Check new active slave

cat /proc/net/bonding/bond0 | grep "Currently Active Slave"

Test connectivity

ping -c 4 192.168.100.1

Bring primary interface back up

sudo ip link set enp1s0 up

Monitor bond performance

Use monitoring tools to track bond interface performance and verify load balancing behavior.

# Monitor real-time interface statistics
watch -n 1 'cat /proc/net/dev | grep -E "(bond0|enp[12]s0)"'

Check bonding driver information

modinfo bonding

View detailed bond status

cat /proc/net/bonding/bond0

Configure VLAN switching and routing

Set up advanced VLAN routing to enable communication between different network segments through your bonded interface.

Enable IP forwarding

Configure the system to forward packets between VLAN interfaces for inter-VLAN routing.

echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Configure VLAN routing rules

Set up routing rules to control traffic flow between different VLAN segments.

# Add routing rules for VLAN communication
sudo ip route add 192.168.200.0/24 via 192.168.100.1 dev bond0.100
sudo ip route add 192.168.300.0/24 via 192.168.100.1 dev bond0.100

Make routes persistent

echo '192.168.200.0/24 via 192.168.100.1 dev bond0.100' | sudo tee -a /etc/systemd/network/bond0.network echo '192.168.300.0/24 via 192.168.100.1 dev bond0.100' | sudo tee -a /etc/systemd/network/bond0.network

Verify your setup

Confirm that your network bonding and VLAN configuration is working correctly across all interfaces.

# Check bond interface status
ip link show bond0
cat /proc/net/bonding/bond0

Verify VLAN interfaces

ip addr show bond0.100 ip addr show bond0.200

Test connectivity on each VLAN

ping -I bond0.100 -c 4 192.168.100.1 ping -I bond0.200 -c 4 192.168.200.1

Check routing table

ip route show

Verify bond mode and parameters

ethtool bond0

Monitor bond statistics

cat /sys/class/net/bond0/statistics/rx_bytes cat /sys/class/net/bond0/statistics/tx_bytes

Troubleshoot common bonding and VLAN issues

Use these diagnostic steps to identify and resolve network bonding problems.

Warning: Never use chmod 777 to fix permission issues. Network configuration files should have 644 permissions with root ownership for security.
SymptomCauseFix
Bond interface not createdBonding module not loadedsudo modprobe bonding; echo bonding | sudo tee -a /etc/modules
Slave interfaces not bondingInterfaces already configured with IPsudo ip addr flush dev enp1s0; sudo ip addr flush dev enp2s0
VLAN traffic not workingSwitch port not configured as trunkConfigure switch port for VLAN tagging/trunking
Bond failover not workingMII monitoring disabledAdd mii-monitor-interval: 100 to bond parameters
802.3ad mode not workingLACP not enabled on switchEnable LACP on switch port channel
Poor performanceWrong transmit hash policySet transmit-hash-policy: layer3+4 for better distribution
NetworkManager conflictsMultiple network managerssudo systemctl disable NetworkManager or use nmcli exclusively

Security and performance optimization

Implement additional security measures and performance optimizations for your bonded network configuration. This builds on the security practices covered in our nftables security hardening tutorial.

Configure network security

Set up firewall rules specific to your VLAN configuration and enable network security features.

# Configure firewall rules for VLANs
sudo nft add table inet vlan_filter
sudo nft add chain inet vlan_filter input { type filter hook input priority 0\; }
sudo nft add rule inet vlan_filter input iifname "bond0.100" ip saddr 192.168.100.0/24 accept
sudo nft add rule inet vlan_filter input iifname "bond0.200" ip saddr 192.168.200.0/24 accept

Enable ARP filtering to prevent ARP spoofing

echo 'net.ipv4.conf.all.arp_filter=1' | sudo tee -a /etc/sysctl.conf echo 'net.ipv4.conf.bond0.arp_filter=1' | sudo tee -a /etc/sysctl.conf

Optimize network performance

Configure kernel parameters and interface settings for optimal bonding performance.

# Optimize network buffers
echo 'net.core.rmem_max = 134217728' | sudo tee -a /etc/sysctl.conf
echo 'net.core.wmem_max = 134217728' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_rmem = 4096 87380 134217728' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_wmem = 4096 65536 134217728' | sudo tee -a /etc/sysctl.conf

Apply settings

sudo sysctl -p

Configure interface ring buffers

sudo ethtool -G enp1s0 rx 4096 tx 4096 sudo ethtool -G enp2s0 rx 4096 tx 4096

Monitor and maintain bond configuration

Set up comprehensive monitoring and maintenance procedures for your bonded network interfaces. For additional monitoring capabilities, see our Linux performance monitoring tutorial.

Create comprehensive monitoring

Set up detailed logging and alerting for bond interface status changes.

#!/bin/bash

BOND="bond0"
LOG_FILE="/var/log/bond-health.log"
ALERT_EMAIL="admin@example.com"

Function to log with timestamp

log_event() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> $LOG_FILE }

Check bond operational status

if [ ! -f "/proc/net/bonding/$BOND" ]; then log_event "CRITICAL: Bond interface $BOND not found" exit 1 fi

Parse bond status

BOND_MODE=$(grep "Bonding Mode:" /proc/net/bonding/$BOND | cut -d: -f2 | xargs) ACTIVE_SLAVE=$(grep "Currently Active Slave:" /proc/net/bonding/$BOND | cut -d: -f2 | xargs) SLAVE_COUNT=$(grep "Slave Interface:" /proc/net/bonding/$BOND | wc -l) UP_SLAVES=$(grep -A 1 "Slave Interface:" /proc/net/bonding/$BOND | grep "MII Status: up" | wc -l) log_event "Bond $BOND - Mode: $BOND_MODE, Active: $ACTIVE_SLAVE, Slaves: $UP_SLAVES/$SLAVE_COUNT"

Alert on issues

if [ $UP_SLAVES -lt 1 ]; then log_event "ALERT: No active slaves in bond $BOND" fi if [ $UP_SLAVES -eq 1 ] && [ $SLAVE_COUNT -gt 1 ]; then log_event "WARNING: Only one slave active in bond $BOND - redundancy lost" fi
sudo chmod 755 /usr/local/bin/bond-health-check.sh

Add to cron for regular monitoring

echo "/5 * /usr/local/bin/bond-health-check.sh" | sudo crontab -

Common issues

SymptomCauseFix
Bond interface not createdBonding module not loadedsudo modprobe bonding; echo bonding | sudo tee -a /etc/modules
Slave interfaces won't join bondInterfaces have existing IP configurationsudo ip addr flush dev enp1s0; sudo ip addr flush dev enp2s0
VLAN traffic not passingSwitch port not configured as trunkConfigure switch port for 802.1Q trunking
Failover not workingMissing MII monitoringAdd mii-monitor-interval: 100 to bond configuration
802.3ad mode failsLACP not configured on switchEnable LACP/port-channel on connected switch ports
Uneven load distributionSuboptimal hash policyUse transmit-hash-policy: layer3+4 for better balance
Configuration not persistentNetwork manager conflictsUse consistent configuration method (Netplan or NetworkManager)
Poor bonding performanceInterface speed/duplex mismatchsudo ethtool -s enp1s0 speed 1000 duplex full autoneg on

Next steps

Automated install script

Run this to automate the entire setup

#network bonding #vlan tagging #link aggregation #network redundancy #trunk interface

Need help?

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.

Talk to an engineer