Skip to content

Advanced_networking

Comprehensive Guide to Linux Bonding, Bridging, VLANs, and Network Virtualization

Section titled “Comprehensive Guide to Linux Bonding, Bridging, VLANs, and Network Virtualization”

Network bonding combines multiple network interfaces into a single logical interface for increased throughput, redundancy, or both. It’s essential for production environments requiring high availability and performance.

Network Bonding Architecture
+------------------------------------------------------------------+
| |
| Network Bonding |
| |
| +-------------------------------------------------------------+|
| | bond0 (Virtual Interface) ||
| | IP: 192.168.1.10/24 ||
| +---------------------------+-----------------------------------+|
| | |
| +---------------------+---------------------+ |
| | | | |
| v v v |
| +----------+ +----------+ +----------+ |
| | eth0 | | eth1 | | eth2 | |
| | Slave | | Slave | | Slave | |
| +----------+ +----------+ +----------+ |
| |
| Benefits: |
| +----------------------------------------------------------+ |
| | • Increased bandwidth (throughput = sum of all interfaces) | |
| | • Fault tolerance (if one link fails, others take over) | |
| | • Load balancing | |
| | • High availability | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Bonding Modes Comparison
+------------------------------------------------------------------+
| |
| Mode 0: Round-Robin (balance-rr) |
| +----------------------------------------------------------+ |
| | • Packets sent in sequential order across all slaves | |
| | • Provides load balancing and fault tolerance | |
| | • Requires switch support for LACP (not required) | |
| | • Example: eth0→eth1→eth2→eth0→... | |
| +----------------------------------------------------------+ |
| |
| Mode 1: Active-Backup (active-backup) |
| +----------------------------------------------------------+ |
| | • Only one slave active at a time | |
| | • Other slaves standby | |
| | • Failover when active slave fails | |
| | • Simple, widely compatible | |
| | • MAC address always from active slave | |
| +----------------------------------------------------------+ |
| |
| Mode 2: XOR (balance-xor) |
| +----------------------------------------------------------+ |
| | • Uses source MAC XOR destination MAC for selection | |
| | • Provides load balancing and fault tolerance | |
| | • Consistent mapping between source/dest | |
| | • Good for single MAC destination (local switch) | |
| +----------------------------------------------------------+ |
| |
| Mode 3: Broadcast (broadcast) |
| +----------------------------------------------------------+ |
| | • Sends all traffic on all slaves | |
| | • Provides fault tolerance only | |
| | • Should only be used with specific applications | |
| | • Creates duplicate traffic | |
| +----------------------------------------------------------+ |
| |
| Mode 4: 802.3ad (LACP) |
| +----------------------------------------------------------+ |
| | • IEEE 802.3ad Link Aggregation Control Protocol | |
| | • Requires switch with LACP support | |
| | • Dynamic aggregation | |
| | • Best for load balancing with switch awareness | |
| | • Load balancing based on (src,dst) MAC and port | |
| +----------------------------------------------------------+ |
| |
| Mode 5: TLB (balance-tlb) |
| +----------------------------------------------------------+ |
| | • Transmit Load Balancing | |
| | • Outgoing load balanced based on load | |
| | • Incoming from specific slave | |
| | • Does not require special switch configuration | |
| +----------------------------------------------------------+ |
| |
| Mode 6: ALB (balance-alb) |
| +----------------------------------------------------------+ |
| | • Adaptive Load Balancing | |
| | • Includes receive load balancing (ARP) | |
| | • Uses ARP negotiation to balance incoming traffic | |
| | • Does not require switch configuration | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Terminal window
# Create bond interface
sudo ip link add bond0 type bond mode 802.3ad
# Or for active-backup
sudo ip link add bond0 type bond mode active-backup
# Configure bond options
sudo ip link set bond0 type bond miimon 100 # MII monitoring (100ms)
sudo ip link set bond0 type bond lacp_rate fast # LACP rate
sudo ip link set bond0 type bond xmit_hash_policy layer2+3 # Hash policy
# Add slave interfaces
sudo ip link set eth0 master bond0
sudo ip link set eth1 master bond0
# Bring up bond interface
sudo ip link set bond0 up
# Configure IP address
sudo ip addr add 192.168.1.10/24 dev bond0
# Verify bond status
cat /proc/net/bonding/bond0
# Remove slave
sudo ip link set eth0 nomaster
# Delete bond
sudo ip link delete bond0

Configuring Bond via /etc/network/interfaces (Debian/Ubuntu)

Section titled “Configuring Bond via /etc/network/interfaces (Debian/Ubuntu)”
/etc/network/interfaces
# Bond configuration
auto bond0
iface bond0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
bond-mode 802.3ad
bond-miimon 100
bond-lacp-rate fast
bond-slaves eth0 eth1
# Or with DHCP
auto bond0
iface bond0 inet dhcp
bond-mode active-backup
bond-miimon 100
bond-slaves eth0 eth1

Configuring Bond via Network Scripts (RHEL/CentOS)

Section titled “Configuring Bond via Network Scripts (RHEL/CentOS)”
/etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
NAME=bond0
TYPE=Bond
BONDING_MASTER=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT=yes
BOOTPROTO=none
BONDING_OPTS="mode=4 miimon=100 lacp_rate=fast xmit_hash_policy=layer2+3"
# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
# /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
NAME=eth1
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
# Restart network
sudo systemctl restart network
Bonding Module Options
+------------------------------------------------------------------+
| |
| Option | Description | Default |
| --------------------|--------------------------------|---------|
| miimon | MII link monitoring interval | 0 |
| updelay | Delay before link up | 0 |
| downdelay | Delay before link down | 0 |
| mode | Bonding mode (0-6) | 0 |
| xmit_hash_policy | Traffic distribution policy | layer2 |
| lacp_rate | LACP rate (slow/fast) | slow |
| max_bonds | Maximum bond devices | 1 |
| primary | Primary slave for mode 1 | none |
| fail_over_mac | MAC on failover (active-backup)| none |
| |
| xmit_hash_policy options: |
| +----------------------------------------------------------+ |
| | layer2 | XOR of source/dest MAC | |
| | layer2+3 | XOR of MAC + IP (recommended) | |
| | layer3+4 | XOR of IP + Port | |
| +----------------------------------------------------------+ |
| |
| miimon: 100ms recommended for most environments |
| |
+------------------------------------------------------------------+

A network bridge connects multiple network segments at layer 2 (Data Link Layer). It’s commonly used in virtualization, containers, and network segmentation.

Network Bridging Architecture
+------------------------------------------------------------------+
| |
| Bridge (br0) |
| +------------------------------------------------------------+ |
| | Layer 2 Switch | |
| | | |
| | +--------+ +--------+ +--------+ +--------+ | |
| | | eth0 | | eth1 | | veth0 | | veth1 | | |
| | | (port) | | (port) | | (port) | | (port) | | |
| | +--------+ +--------+ +--------+ +--------+ | |
| | | |
| | IP: 192.168.1.1/24 | |
| +------------------------------------------------------------+ |
| | |
| v |
| +------------------------------------------------------------+ |
| | Connected to physical network | |
| +------------------------------------------------------------+ |
| |
| Use Cases: |
| +----------------------------------------------------------+ |
| | • KVM/QEMU virtualization | |
| | • Docker bridge networks | |
| | • Network segmentation | |
| | • Bridging physical and virtual networks | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Terminal window
# Create bridge interface
sudo ip link add br0 type bridge
# Or with STP enabled
sudo ip link add br0 type bridge stp_state 1 forward_delay 2
# Add interfaces to bridge
sudo ip link set eth0 master br0
sudo ip link set eth1 master br0
sudo ip link set veth0 master br0
# Configure IP on bridge
sudo ip addr add 192.168.1.1/24 dev br0
# Bring up bridge
sudo ip link set br0 up
# Verify
ip link show
bridge link show
bridge -d link show
# Remove interface from bridge
sudo ip link set eth0 nomaster
# Delete bridge
sudo ip link delete br0
Terminal window
# Create bridge using nmcli
nmcli con add type bridge ifname br0 con-name br0
nmcli con add type bridge-slave ifname eth0 master br0
# Configure IP
nmcli con modify br0 ipv4.addresses 192.168.1.1/24
nmcli con modify br0 ipv4.method manual
# Activate
nmcli con up br0
# View bridge
nmcli dev show br0
bridge -d link show
/etc/sysconfig/network-scripts/ifcfg-br0
# Create bridge for KVM
DEVICE=br0
NAME=br0
TYPE=Bridge
IPADDR=192.168.1.1
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
# Physical interface (remove IP)
# /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
BRIDGE=br0
# Restart network
sudo systemctl restart network
# Verify
brctl show
ip addr show br0
Bridge Options
+------------------------------------------------------------------+
| |
| Option | Description |
| --------------------|-------------------------------------------|
| bridge-name | Bridge interface name |
| aging_time | MAC address table aging time |
| forward_delay | Time in forwarding state before learning|
| hello_time | Hello packet interval |
| max_age | Max message age for topology |
| stp_state | STP enabled (1) or disabled (0) |
| priority | Bridge priority for STP |
| port_priority | Port priority for STP |
| path_cost | Port path cost for STP |
| |
| Common configurations: |
| +----------------------------------------------------------+ |
| | # With STP (for networks with loops) | |
| | ip link add br0 type bridge stp_state 1 forward_delay 2 | |
| | | |
| | # Without STP (simple bridge) | |
| | ip link add br0 type bridge stp_state 0 | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

VLANs allow you to segment a network at Layer 2. Each VLAN is identified by a 12-bit VLAN ID (1-4094). Traffic between VLANs requires Layer 3 routing.

VLAN Architecture
+------------------------------------------------------------------+
| |
| Physical Switch |
| +------------------------------------------------------------+ |
| | | |
| | +--------+ +--------+ +--------+ +--------+ | |
| | | VLAN 10| | VLAN 20| | VLAN 30| | VLAN 40| | |
| | | (Mgmt) | | (Data) | | (Voice)| | (Guest)| | |
| | +--------+ +--------+ +--------+ +--------+ | |
| | | | | | | |
| +-------+----------+----------+----------+--------------------+ |
| | |
| v |
| +------------------------------------------------------------+ |
| | Linux with VLANs | |
| | | |
| | +-----------+ +-----------+ +-----------+ | |
| | | eth0.10 | | eth0.20 | | eth0.30 | | |
| | | 10.0.10.x | | 10.0.20.x | | 10.0.30.x | | |
| | +-----------+ +-----------+ +-----------+ | |
| | | |
| | Parent: eth0 (trunk) | |
| +------------------------------------------------------------+ |
| |
| VLAN Tagging (802.1Q): |
| +----------------------------------------------------------+ |
| | • Adds 4-byte tag to Ethernet frame | |
| | • Tag contains VLAN ID (12 bits) | |
| | • Switch port must be in trunk mode | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Terminal window
# Create VLAN interface using ip
sudo ip link add link eth0 name eth0.100 type vlan id 100
# Configure IP
sudo ip addr add 10.0.100.1/24 dev eth0.100
# Bring up
sudo ip link set eth0.100 up
# Or use vlan package
sudo apt install vlan
sudo vconfig add eth0 100
sudo ip addr add 10.0.100.1/24 dev eth0.100
sudo ip link set eth0.100 up
# View VLAN interfaces
ip -d link show
cat /proc/net/vlan/config
# Remove VLAN
sudo ip link delete eth0.100
/etc/network/interfaces
# Physical interface (trunk port)
auto eth0
iface eth0 inet manual
up ip link set eth0 up
down ip link set eth0 down
# VLAN 10
auto eth0.10
iface eth0.10 inet static
address 10.0.10.10
netmask 255.255.255.0
vlan-raw-device eth0
# VLAN 20
auto eth0.20
iface eth0.20 inet static
address 10.0.20.10
netmask 255.255.255.0
vlan-raw-device eth0
Terminal window
# Create VLAN using nmcli
nmcli con add type vlan ifname eth0.100 dev eth0 id 100
# Configure IP
nmcli con modify vlan-eth0.100 ipv4.addresses 10.0.100.10/24
nmcli con modify vlan-eth0.100 ipv4.method manual
# Activate
nmcli con up vlan-eth0.100
# View VLANs
nmcli device show
Terminal window
# QinQ - Double tagging for service provider VLANs
sudo ip link add link eth0 name eth0.100.200 type vlan id 200 proto 802.1ad
# Or use vconfig
sudo vconfig set_flag eth0.100 1 1 # Enable QinQ
sudo vconfig add eth0.100 200
# QinQ configuration
# Inner VLAN: 100
# Outer VLAN: 200

Network namespaces provide isolated network stacks. Each namespace has its own network interfaces, routing tables, and iptables rules.

Network Namespaces
+------------------------------------------------------------------+
| |
| Host Network Stack |
| +------------------------------------------------------------+ |
| | eth0 | lo | eth1 | routes | iptables | ARP table | |
| +------------------------------------------------------------+ |
| | |
| v |
| +------------------+ +------------------+ |
| | ns-default | | ns-custom | |
| +------------------+ +------------------+ |
| | veth-a | | veth-b | |
| | lo | | lo | |
| | routes | | routes | |
| | iptables | | iptables | |
| +------------------+ +------------------+ |
| | |
| v |
| +------------------+ +------------------+ |
| | ns-frontend | | ns-backend | |
| +------------------+ +------------------+ |
| | veth-c | | veth-d | |
| | lo | | lo | |
| +------------------+ +------------------+ |
| |
| Use Cases: |
| +----------------------------------------------------------+ |
| | • Container isolation (Docker, LXC) | |
| | • VPN isolation | |
| | • Network testing | |
| | • Multi-tenant environments | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+
Terminal window
# Create namespace
sudo ip netns add frontend
# List namespaces
ip netns list
# Execute command in namespace
ip netns exec frontend ip link
ip netns exec frontend ip addr
# Add interface to namespace
# First create veth pair
sudo ip link add veth0 type veth peer name veth1
# Move one end to namespace
sudo ip link set veth1 netns frontend
# Configure in namespace
sudo ip netns exec frontend ip addr add 10.0.0.1/24 dev veth1
sudo ip netns exec frontend ip link set veth1 up
# Delete namespace
sudo ip netns delete frontend
# Run shell in namespace
sudo ip netns exec frontend /bin/bash
Terminal window
# Create bridge
sudo ip link add br0 type bridge
# Create veth pairs for each namespace
sudo ip link add veth0 type veth peer name veth0ns
sudo ip link add veth1 type veth peer name veth1ns
# Move one end to namespaces
sudo ip link set veth0ns netns ns1
sudo ip link set veth1ns netns ns2
# Add bridge ports
sudo ip link set veth0 master br0
sudo ip link set veth1 master br0
# Configure IPs and bring up
sudo ip addr add 10.0.1.1/24 dev veth0
sudo ip netns exec ns1 ip addr add 10.0.1.2/24 dev veth0ns
sudo ip addr add 10.0.1.3/24 dev veth1
sudo ip netns exec ns2 ip addr add 10.0.1.4/24 dev veth1ns
# Bring up everything
sudo ip link set br0 up
sudo ip link set veth0 up
sudo ip link set veth1 up
sudo ip netns exec ns1 ip link set veth0ns up
sudo ip netns exec ns2 ip link set veth1ns up
# Enable forwarding in namespaces for routing
sudo ip netns exec ns1 sysctl -w net.ipv4.ip_forward=1

veth pairs are virtual Ethernet cables that connect two network namespaces. They’re the building blocks for container networking.

veth Pair Architecture
+------------------------------------------------------------------+
| |
| +------------------+ +------------------+ |
| | Namespace A | | Namespace B | |
| | | | | |
| | +----------+ | | +----------+ | |
| | | veth-A |==+==========+ | veth-B | | |
| | +----------+ | | +----------+ | |
| | | | | | | |
| +---------|--------+ +---------|---------+ |
| v v |
| +------------------+ +------------------+ |
| | Host Kernel | | Host Kernel | |
| +------------------+ +------------------+ |
| |
| Traffic flows: veth-A ←→ veth-B |
| |
+------------------------------------------------------------------+
Terminal window
# Create veth pair
sudo ip link add veth0 type veth peer name veth1
# Configure each end
sudo ip addr add 10.0.0.1/24 dev veth0
sudo ip addr add 10.0.0.2/24 dev veth1
# Bring up
sudo ip link set veth0 up
sudo ip link set veth1 up
# Move one end to namespace (see above)
# Check
ip link show
ip addr show veth0
# Delete veth pair
sudo ip link delete veth0

Terminal window
# GRE Tunnel
# On endpoint A
sudo ip tunnel add gre0 mode gre remote 192.168.1.2 local 192.168.1.1
sudo ip addr add 10.0.0.1/30 dev gre0
sudo ip link set gre0 up
# On endpoint B
sudo ip tunnel add gre0 mode gre remote 192.168.1.1 local 192.168.1.2
sudo ip addr add 10.0.0.2/30 dev gre0
sudo ip link set gre0 up
# Verify
ip tunnel show
ping 10.0.0.2
# IPIP Tunnel (simpler)
sudo ip tunnel add tun0 mode ipip remote 192.168.1.2 local 192.168.1.1
sudo ip addr add 10.0.0.1/30 dev tun0
sudo ip link set tun0 up
# VXLAN (Layer 2 over Layer 3)
sudo ip link add vxlan0 type vxlan id 100 remote 192.168.1.2 \
dstport 4789 local 192.168.1.1
sudo ip addr add 10.0.100.1/24 dev vxlan0
sudo ip link set vxlan0 up
Terminal window
# Install
sudo apt install wireguard
# Generate keys
wg genkey | tee private.key | wg pubkey > public.key
# Server configuration
# /etc/wireguard/wg0.conf
[Interface]
PrivateKey = <server-private-key>
Address = 10.0.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i %i -j ACCEPT
PostUp = iptables -A FORWARD -o %i -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey = <client-public-key>
AllowedIPs = 10.0.0.2/32
# Client configuration
[Interface]
PrivateKey = <client-private-key>
Address = 10.0.0.2/24
[Peer]
PublicKey = <server-public-key>
Endpoint = server.example.com:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
# Enable
sudo wg-quick up wg0
sudo wg show

Terminal window
# Check bond status
cat /proc/net/bonding/bond0
# Check bridge
bridge link show
brctl show
bridge -d link show
# Check VLAN
cat /proc/net/vlan/config
ip -d link show
# Check namespace
ip netns list
ip netns exec <ns> ip addr
# Check veth
ip link show type veth
ethtool <interface>
# Packet forwarding
cat /proc/sys/net/ipv4/ip_forward
sysctl net.ipv4.ip_forward
# Routing table
ip route show
ip route get 8.8.8.8
# ARP table
ip neigh show
arp -a
# Conntrack
conntrack -L
conntrack -L -p tcp --dport 80
# Network statistics
ss -tunapl
netstat -i

  1. What is network bonding in Linux?

    • Combining multiple network interfaces into one logical interface
  2. What are the different bonding modes?

    • 0 (round-robin), 1 (active-backup), 2 (XOR), 3 (broadcast), 4 (802.3ad/LACP), 5 (TLB), 6 (ALB)
  3. What is a network bridge?

    • Layer 2 device connecting network segments
  4. What is a VLAN?

    • Virtual LAN - network segmentation at Layer 2
  5. What is 802.1Q?

    • VLAN tagging standard
  1. What is the difference between mode 1 and mode 4 bonding?

    • Mode 1: active-backup (one active at a time); Mode 4: LACP (dynamic aggregation)
  2. What is STP and why is it used with bridges?

    • Spanning Tree Protocol prevents loops in bridged networks
  3. What are network namespaces used for?

    • Isolating network stacks for containers, VPNs, testing
  4. What is a veth pair?

    • Virtual ethernet pair - two connected virtual interfaces
  5. How do you configure VLANs in Linux?

    • Using ip link add with type vlan, or vconfig
  1. Explain the difference between TLB and ALB bonding modes

    • TLB: transmit load balancing only; ALB: includes receive load balancing
  2. What is QinQ and when would you use it?

    • Double VLAN tagging; used by service providers for VLAN translation
  3. What is VXLAN and how does it work?

    • Virtual Extensible LAN; MAC-in-UDP tunneling for Layer 2 over Layer 3
  4. How do you debug network bonding issues?

    • Check /proc/net/bonding/bond0, ethtool, switch configuration
  5. What is the difference between bridging and routing?

    • Bridging works at Layer 2, routing at Layer 3

Quick Reference
+------------------------------------------------------------------+
| |
| Bonding: |
| +----------------------------------------------------------+ |
| | ip link add bond0 type bond mode 802.3ad | |
| | ip link set eth0 master bond0 | |
| | cat /proc/net/bonding/bond0 | |
| +----------------------------------------------------------+ |
| |
| Bridging: |
| +----------------------------------------------------------+ |
| | ip link add br0 type bridge | |
| | ip link set eth0 master br0 | |
| | brctl show | |
| +----------------------------------------------------------+ |
| |
| VLANs: |
| +----------------------------------------------------------+ |
| | ip link add link eth0 name eth0.100 type vlan id 100 | |
| | ip -d link show | |
| +----------------------------------------------------------+ |
| |
| Namespaces: |
| +----------------------------------------------------------+ |
| | ip netns add <name> | |
| | ip netns exec <name> <command> | |
| | ip link set <interface> netns <name> | |
| +----------------------------------------------------------+ |
| |
| veth: |
| +----------------------------------------------------------+ |
| | ip link add veth0 type veth peer name veth1 | |
| | ip link set veth1 netns <namespace> | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+