How to Create Virtual NICs Like virbr0-nic for Linux Bridge Networking


2 views

The virbr0-nic interface is a special virtual network interface created by libvirt for bridge networking. Unlike aliased interfaces (eth0:0 style), these are full-fledged virtual NICs with these characteristics:

  • Created specifically as bridge ports
  • Have their own MAC addresses
  • Not tied to physical interfaces
  • Used for virtual machine networking environments

Here's the proper way to create persistent virtual NICs for bridging:

# Create the tap interface
ip tuntap add dev vnic0 mode tap

# Alternatively using the legacy command:
tunctl -t vnic0 -u root -g root

# Bring it up
ip link set vnic0 up

# Add to bridge
brctl addif br0 vnic0

When libvirt creates virbr0-nic during bridge setup, it essentially performs:

# Internal libvirt commands (simplified)
ip link add virbr0-nic type dummy
ip link set virbr0-nic master virbr0
ip link set virbr0-nic up

For a complete KVM setup with custom virtual NICs:

# Create bridge
brctl addbr vmbr0
ip addr add 192.168.100.1/24 dev vmbr0
ip link set vmbr0 up

# Create virtual NIC
ip link add vnet-host type dummy
ip link set vnet-host master vmbr0

# Configure iptables for NAT
iptables -t nat -A POSTROUTING -s 192.168.100.0/24 ! -d 192.168.100.0/24 -j MASQUERADE

If your virtual NIC isn't working:

  • Check bridge membership: brctl show
  • Verify interface state: ip link show vnic0
  • Ensure proper permissions (for tap devices)
  • Check kernel modules: lsmod | grep tun

For Debian/Ubuntu systems, add to /etc/network/interfaces:

auto vmbr0
iface vmbr0 inet static
    address 192.168.100.1
    netmask 255.255.255.0
    bridge_ports vnet-host
    bridge_stp off
    bridge_fd 0

For RHEL/CentOS, create /etc/sysconfig/network-scripts/ifcfg-vnet-host:

DEVICE=vnet-host
TYPE=Ethernet
BRIDGE=vmbr0
ONBOOT=yes

The virbr0-nic interface you're observing is automatically created by libvirt's default network configuration. This virtual NIC serves as the bridge's "anchor" interface, allowing the bridge to exist even when no guest VMs are connected. Here's how it differs from traditional aliases like eth0:0:

# Traditional alias interface
ifconfig eth0:0 192.168.1.100 netmask 255.255.255.0 up

# libvirt-created bridge interface
brctl addbr virbr0
ip tuntap add virbr0-nic mode tap

To manually create a virtual NIC attached to a bridge without physical interfaces, use these methods:

Method 1: Using iproute2 (Preferred)

# Create tap interface
sudo ip tuntap add dev myvnic0 mode tap

# Create bridge if not existing
sudo ip link add name mybr0 type bridge

# Attach interface to bridge
sudo ip link set myvnic0 master mybr0

# Bring up interfaces
sudo ip link set myvnic0 up
sudo ip link set mybr0 up

Method 2: Using brctl (Legacy)

# Install bridge-utils if needed
sudo apt-get install bridge-utils

# Create bridge
sudo brctl addbr mybr0

# Create persistent TAP device
sudo tunctl -t myvnic0 -u $(whoami)

# Attach to bridge
sudo brctl addif mybr0 myvnic0

# Set interfaces up
sudo ip link set myvnic0 up
sudo ip link set mybr0 up

The vnet1 interface in your example represents a virtual NIC assigned to a running KVM guest. These are automatically managed by libvirt when VMs start/stop. Key characteristics:

  • Created via QEMU's -netdev tap backend
  • Temporary (disappears when VM shuts down)
  • Named sequentially (vnet0, vnet1, etc.)

For interfaces that persist across reboots, create a network configuration file in /etc/network/interfaces.d/:

# /etc/network/interfaces.d/mybridge.conf
auto mybr0
iface mybr0 inet static
    bridge_ports myvnic0
    address 192.168.100.1
    netmask 255.255.255.0

auto myvnic0
iface myvnic0 inet manual
    pre-up ip tuntap add dev myvnic0 mode tap user root
    post-down ip tuntap del dev myvnic0 mode tap

Common issues and solutions:

# Check bridge membership
bridge link show

# Verify interface exists
ip link show type tap

# Check kernel module support
lsmod | grep tun

# Debug creation errors
journalctl -xe -n 50