Advanced
Searching inHow-to guides
How to search
  • Type the task in your own words (find port, open firewall, disk full) or paste an error message in quotes.
  • Choose "Quick answer" to see only the commands, or an area to stay in one field.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

How-to 231Network · Linux

How to create a bridge or VLAN with nmcli

A KVM host needs a bridge so its VMs sit directly in the office network; a server must reach a second network on VLAN 20 over the same cable. On RHEL and most current distributions, NetworkManager does both with nmcli — persistent, without editing files by hand. This how-to creates a VLAN interface, a bridge with the physical port in it, and moves the IP address safely so you do not lose the connection.

  • 5 Lessons
  • 5 Commands

$ run as a normal user# run as root (or with sudo)

231.1

The quick answer

nmcli connection add type vlan con-name vlan20 ifname eth0.20 dev eth0 id 20 ipv4.method manual ipv4.addresses 10.20.0.15/24
nmcli connection up vlan20
nmcli connection add type bridge con-name br0 ifname br0 ipv4.method manual ipv4.addresses 192.168.1.10/24 ipv4.gateway 192.168.1.1 ipv4.dns 192.168.1.1 bridge.stp no
nmcli connection add type bridge-slave con-name br0-port1 ifname eth1 master br0
nmcli connection up br0

Commands in this lesson

231.2

Step by step

  1. Look first — nmcli device status and nmcli connection show list interfaces and their profiles. Note the current IP, gateway and DNS.
  2. VLAN (lines 1–2) — the switch port must carry VLAN 20 tagged (trunk). The new interface eth0.20 gets its own address; eth0 keeps its untagged network.
  3. Bridge (line 3) — br0 gets the IP address that the physical port had. STP off is fine for a simple host with one uplink.
  4. Add the port (line 4) — eth1 becomes a member of br0 and has no IP of its own any more.
  5. Switch over without losing SSH — do it from the console, or in one command with a safety net:
echo "nmcli connection up 'Wired connection 2'" | at now + 5 minutes
nmcli connection down 'Wired connection 2'; nmcli connection up br0

If SSH works on the bridge IP, cancel the at job and delete the old profile (nmcli connection delete 'Wired connection 2').

  1. VLAN on top of a bridge (VMs in VLAN 20): create the VLAN on eth1 (dev eth1 id 20) without an IP, and make it the port of a second bridge br20.
  2. Use it — KVM/libvirt VMs: network source "bridge br0". Containers can use it with a macvlan or bridge network.
  3. Check with ip -d link show eth0.20 (shows vlan id 20) and bridge link (shows eth1 master br0).

231.3

Check that it worked

nmcli -f NAME,DEVICE,STATE connection show --active lists br0, br0-port1 and vlan20 as activated; ip -br addr shows 192.168.1.10/24 on br0 (not on eth1) and 10.20.0.15/24 on eth0.20; ping 10.20.0.1 works; after a reboot all is the same.

231.4

Common problems

ProblemCauseFix
SSH lost while switchingIP moved off the old interface before the bridge came up.Console, or the at safety net; do it in one command.
VLAN interface up but no trafficSwitch port not tagged for VLAN 20.Ask for a trunk with VLAN 20 tagged.
Bridge has no IP after rebootOld profile of eth1 still active and wins.Delete the old profile; connection.autoconnect yes on br0.
VMs get no DHCP on the bridgeWi-Fi port as bridge member, or the network blocks extra MAC addresses.Use wired ports; allow MAC addresses on the switch / hypervisor.
Interface name too longVLAN names over 15 characters.Shorter ifname (for example vl20).
Firewall blocks bridged trafficbr_netfilter sends bridged packets through the firewall.Allow it in the firewall, or set the bridge sysctls to 0 on pure VM hosts.

Commands in this lesson

231.5

Go further

1Why does the bridge port lose its own IP address?

The port only carries traffic into the bridge; the bridge interface itself holds the address.

2What must the switch do for a VLAN interface to work?

The switch port must send that VLAN tagged (a trunk port).

All commands in this chapter