From 3fb70d2c3fc327d83162455a4259dfdcbe062194 Mon Sep 17 00:00:00 2001 From: Nathan Steel Date: Fri, 14 Apr 2023 17:19:34 -0400 Subject: [PATCH] Correct and improve bridge network guide --- guides/setup-kvm-bridge.html | 81 ++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/guides/setup-kvm-bridge.html b/guides/setup-kvm-bridge.html index 186e5cc..0a2d91d 100644 --- a/guides/setup-kvm-bridge.html +++ b/guides/setup-kvm-bridge.html @@ -33,69 +33,68 @@
-

A bridge network is a means to connect/bridge different networks together to act like a single network. In this case, it allows any connections to the bridge network to get their own internal IPs, as if plugged into the network directly, and work as you'd expect a completely new physical PC to work. i.e. Accessble to other clients outside of the host.

+

A bridge network is a means to connect/bridge different networks together to act as a single network. In this case, it allows any virtual connections to the bridge network to get their own internal IPs, as if plugged into the network directly.

+

Install bridge-utils

sudo apt install bridge-utils
-

Find the network to bridge

-

First we need to find the network we want to bridge to the VMs

-
ip a
+

Find the network device to bridge

+

First we need to find the network device we want to bridge to the VMs.

+
ip link
+

You'll likely have a device called something similar to enp1s0, or eth0.

-

Bridge it

+

Create the bridge network

This will be familiar to those who have set a static ip on linux, as it's essentially the same, with a few additional lines related to bridging

-

This can be done by editing /etc/network/interfaces

+

Remove interface from interfaces file

+

First step is to remove any references to your network device from /etc/network/interfaces, if this file is untouched there will likely be two lines at the bottom.

sudo vim /etc/network/interfaces
-

And setting the following lines

- -

Change existing port to manual

-

There will already exist some lines with your chosen network adapter, such as

-
iface enp2s0 inet auto
-

Change this to contain manual instead

-
iface enp2s0 inet manual
-

Static Bridge

-

If you want your server to have a static IP use this

+

Create a new bridge interface

+

Now create a file in the /etc/network/interfaces.d/ directory, with the name of your bridge (I like br0).

+

Static IP

auto br0
-iface br0 inet static
-	bridge_ports enp2s0 # which port(s) to bridge together
-                address 192.168.0.100 # Static IP
-                netmask 255.255.255.0
-                network 192.168.0.1
-                broadcast 192.168.0.255
-                gateway 192.168.0.1
-                bridge_stp off # New
-                bridge_fd 0 # New
-                bridge_maxwait 0 # New
-                dns-nameservers 8.8.8.8 8.8.1.1
-

Dynamic Bridge

-

If instead you wish your server to have a dynamic IP (not recommended). A bridged network can be set, with a dynamic DHCP set IP

+iface br0 inet static # Name the same as your file (br0) + address 192.168.0.100 + broadcast 192.168.0.255 + netmask 255.255.255.0 + gateway 192.168.0.1 # Normally your router's IP + dns-nameservers 192.168.0.1 8.8.8.8 8.8.4.4 # Don't set if resolveconf is installed, comment if internet borked + bridge_ports enp1s0 # Your device name + bridge_stp off # Disable Spanning Tree Protocol + bridge_waitport 0 # No delay before a port becomes available + bridge_fd 0 # No forwarding delay (Connects to network immediately) +

Dynamic IP

iface br0 inet dhcp
     bridge_ports enp2s0
-

Create Virtual Network

-

To make it easier to manage with VMs, this new bridge can be made into a Virtual Network.

-

Open up a text-editor, and create a file called bridged-network.xml

-
vim bridged-network.xml
+

(Optional) Create Virtual Network

+

To make it easier to manage with VMs, this new bridge can also be made into a Virtual Network (Basically so you can select it from a dropdown).

+

Create XML file

+

Open up a text-editor, and create a file called br0.xml, named after the bridge itself.

+
vim br0.xml

Enter the following, then save

<network>
-	<name>bridged-network</name>
+	<name>br0</name>
 	<forward mode="bridge"/>
 	<bridge name="br0"/>
 </network>
-

Then pass the file to virsh net-define

-
sudo virsh net-define bridged-network.xml
-

Active, and auto-start the new network

-
sudo virsh net-start bridged-network
-
sudo virsh net-autostart bridged-network
+ +

Create the virtual network

+
sudo virsh net-define br0.xml
+

Activate, and auto-start (on boot) the new network.

+
sudo virsh net-start br0
+
sudo virsh net-autostart br0
+

You can now remove the br0.xml file.

Reload the network

sudo systemctl restart networking
-

If this creates the bridge, but claims to have failed, restart your PC

+

This may claim to have failed, but if checking with ip link shows the bridge, reboot. Essentially the bridge has been brought up, and it's trying to bring it up again (and can't), then throws an error.

sudo reboot

Check it's there

-

Run another check for networks, and you should now see br0

-
ip a
+				

Run some checks and you should now see br0, with an IP4 address.

+
ip a
+
ping google.co.uk