In this post, we’ll go through the steps to create a network bridge br0 on an Arch Linux system, linking it to the physical Ethernet interface enp6s0. We will also set up a systemd service to handle the creation and removal of the bridge on demand, ensuring that the network configuration remains consistent using NetworkManager.

Step 1: Install Necessary Packages

First, make sure you have the necessary packages installed:

sudo pacman -Syu iproute2 networkmanager

Step 2: Create the Bridge Setup Script

Create a script to set up the bridge br0 and add enp6s0 to it.

sudo nano /usr/local/bin/setup-bridge.sh

Add the following content to the script:

#!/bin/bash

# Disable the enp6s0 connection in NetworkManager
nmcli dev disconnect enp6s0

# Create the bridge
ip link add name br0 type bridge

# Assign the enp6s0 interface to the bridge
ip link set enp6s0 master br0

# Bring up the bridge interface
ip link set br0 up

# Reconnect the bridge in NetworkManager
nmcli con add type bridge ifname br0
nmcli con add type bridge-slave ifname enp6s0 master br0

# Bring up the connections in NetworkManager
nmcli con up bridge-br0
nmcli con up bridge-slave-enp6s0

Make the script executable:

sudo chmod +x /usr/local/bin/setup-bridge.sh

Step 3: Create the Bridge Teardown Script

Create a script to tear down the bridge and restore the original network configuration.

sudo nano /usr/local/bin/teardown-bridge.sh

Add the following content to the script:

#!/bin/bash

# Disconnect the bridge connections in NetworkManager
nmcli con down bridge-br0
nmcli con down bridge-slave-enp6s0

# Remove the bridge connections in NetworkManager
nmcli con delete bridge-br0
nmcli con delete bridge-slave-enp6s0

# Remove enp6s0 from the bridge
ip link set enp6s0 nomaster

# Bring down the bridge interface
ip link set br0 down

# Delete the bridge
ip link delete br0

# Reconnect enp6s0 in NetworkManager
nmcli dev connect enp6s0

Make the script executable:

sudo chmod +x /usr/local/bin/teardown-bridge.sh

Step 4: Create the Systemd Service File

Create a systemd service file that uses these scripts.

sudo nano /etc/systemd/system/bridge-setup.service

Add the following content to the service file:

[Unit]
Description=Set up network bridge br0 with enp6s0
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/setup-bridge.sh
ExecStop=/usr/local/bin/teardown-bridge.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Step 5: Enable and Use the Service

Reload the systemd configuration to apply the changes:

sudo systemctl daemon-reload

Enable the service so it is available but not started at boot:

sudo systemctl enable bridge-setup.service

Now you can start the service on demand:

sudo systemctl start bridge-setup.service

When you want to stop the bridge and restore the original state:

sudo systemctl stop bridge-setup.service

Step 6: Verify the Configuration

After starting the service, verify that the bridge is correctly configured and that enp6s0 is part of it:

ip addr show br0

Ensure that the br0 interface is up and has the correct IP configuration.

To check the status of the bridge and the connection in NetworkManager:

nmcli con show

You should see the bridge-br0 and bridge-slave-enp6s0 connections listed.

Summary

This setup provides a robust method to create and manage a network bridge on an Arch Linux system using enp6s0. By leveraging NetworkManager’s nmcli tool, we ensure that the network configuration remains consistent when the bridge is created or removed.

With this approach, you can start and stop the bridge setup service on demand, allowing you to dynamically manage your network interfaces as needed. This flexibility can be particularly useful in various network scenarios, ensuring that your system adapts seamlessly to changing requirements.

By following these steps, you can confidently manage network bridges on your Arch Linux system, maintaining a stable and consistent network environment.

How to Create and Manage a Network Bridge br0 on Arch Linux Using enp6s0

Johannes Rest


.NET Architekt und Entwickler


Beitragsnavigation


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert