Create a bridge network

When creating a vm with virtmanager in Manjaro the default network interface will be on a NAT network. This will give you an IP off the local network and allow access between the host and vm. You can utilize NAT to port forward but if you need local network access to the VM from the local network you will want to create a bridge interface that will provide the VM access to the local network and get an IP accessible by other machines on the network.

Below are the steps for using Network Manager

in network manager you can manage the bridge via the GUI. Here we will create the bridge with the command line first

sudo nmcli con add ifname br1 type bridge con-name br1
sudo nmcli con add type bridge-slave ifname enp0s13f0u3 master br1
nmcli connection show
nmcli -f bridge con show br1

Once the bridge device is created we can bring down the ethernet interface and bring up the bridge interface.

sudo nmcli con down "Wired connection 1"
sudo nmcli con up br1
nmcli connection show
nmcli con show                                                                                                                          ✔ 
NAME                    UUID                                  TYPE       DEVICE      
br1                     7b4d6ff8-25fd-4c1e-ba9c-490cf922eafd  bridge     br1         
br1 port 1              e765b22d-ec5b-4d27-8c04-3f5a843fc5c4  ethernet   enp0s13f0u3 
Code language: JavaScript (javascript)

Now you can open Virtmanager and add a network adapter make the network source a bridged device and set the device name to br1

Below are the steps to complete this using netctl

if you use this method you will want to disable Network Manager as it will take over and interrupt the connection.

Create Tap interface and get ethernet device name

create a tap interface and get the device name of the local ethernet adapter in this example my ethernet adapter is enp0s13f0u3

#ip a
2: enp0s13f0u3: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether a0:29:19:89:c3:c1 brd ff:ff:ff:ff:ff:ff

Code language: PHP (php)

now create a tap interface named tap0 and set the device state to up

sudo ip tuntap add mode tap tap0
sudo ip link set dev tap0 up Code language: JavaScript (javascript)

Create kvm-bridge configuration file

Now create a configuration file in /etc/netctl named kvm-bridge this will create a br1 device with the ethernet and tap interfaces and enable DHCP the ExecUpPost sets the mac address to the ethernet mac address.

Description="Bridge Interface br1 : enp0s13f0u3,tap0"
Interface=br1
Connection=bridge
BindsToInterfaces=(enp0s13f0u3 tap0)
IP=dhcp
ExecUpPost="ip link set dev br1 address $(cat /sys/class/net/enp0s13f0u3/address); IP=dhcp; ip_set"
ExecDownPre="IP=dhcp" 


## Ignore (R)STP and immediately activate the bridge
SkipForwardingDelay=yes

Enable and start the bridge

Run the following commands to enable and start the bridge

sudo netctl enable kvm-bridge 
sudo netctl start kvm-bridge 

Now the bridge interface should be created you can verify with

sudo bridge link                                                                                                             ✔ 
2: enp0s13f0u3: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 master br1 state forwarding priority 32 cost 5 
7: tap0: <NO-CARRIER,BROADCAST,MULTICAST,PROMISC,UP> mtu 1500 master br1 state disabled priority 32 cost 2 


sudo brctl show
bridge name	bridge id		STP enabled	interfaces
br1		8000.a0291989c3c1	no		enp0s13f0u3
							tap0Code language: HTML, XML (xml)

This show that the bridge is creates and you will see a new br1 device that should get a DHCP address from the local network.

Set VMs to use br1 device

Now in virt manager you can set the VMs network interface to br1 this will allow the machine to get a DHCP address from the local network

Read full article here

Related posts

Leave A Comment