Persistent Configuration - Mellanox/mlxsw GitHub Wiki
Sometimes it is desirable to have the network configuration persist
across reboots. This section describes how to achieve that using
systemd.
This section assumes systemd is used as the service manager on the
system and that NetworkManager is disabled. To disable
NetworkManger, which is mainly aimed at desktop environments, run:
$ systemctl disable NetworkManager
In addition, systemd-networkd needs to be enabled:
$ systemctl enable systemd-networkd
To prevent systemd from waiting until all the links are configured,
edit the following file as specified below:
# /usr/lib/systemd/system/systemd-networkd-wait-online.service
...
ExecStart=/usr/lib/systemd/systemd-networkd-wait-online -i <mgmt>
...
Where <mgmt> is replaced with the name of the management interface
(e.g., enp0s20f0). This will make systemd only wait for the management
interface to be configured and gain carrier.
To split a port during system initialization and have the configuration
persist across reboots, it is possible to use a systemd service unit
file.
# /etc/systemd/system/[email protected]
[Unit]
Description=Split port sw1p%i by 4
Documentation=man:devlink-port(8)
After=network.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/devlink port split sw1p%i count 4
ExecStop=/usr/sbin/devlink port unsplit sw1p%is0
[Install]
WantedBy=multi-user.target
The above service will split port sw1p12 by 4 when executed:
$ systemctl start split-port@12
And unsplit the port when stopped:
$ systemctl stop split-port@12
To have the port split during system initialization, enable the
port-split service:
$ systemctl enable split-port@12
The previously described method will not automatically split the port in case the driver is removed and then loaded again.
It is possible to automatically split the port when it appears using
udev:
# /etc/udev/rules.d/10-local.rules
SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}=="<phys_switch_id>", \
ATTR{phys_port_name}=="p12", ENV{SYSTEMD_WANTS}="[email protected]"
# /etc/systemd/system/[email protected]
[Unit]
Description=Split port sw1p%i by 4
Documentation=man:devlink-port(8)
[Service]
Type=simple
ExecStart=/usr/sbin/devlink port split sw1p%i count 4
systemd can configure many aspects of the network. To see the full
list of possible configuration options please refer to the Further
Resources section.
The example below shows how to create a VLAN-aware bridge between two switch ports.
# /etc/systemd/network/25-bridge.netdev
[NetDev]
Description=Simple VLAN-aware bridge
Name=br0
Kind=bridge
[Bridge]
DefaultPVID=1
VLANFiltering=true
# /etc/systemd/network/25-bridge.network
[Match]
Name=br0
[Network]
Address=192.0.2.1/24
# /etc/systemd/network/25-bridge-slave-1.network
[Match]
Name=sw1p1
[Network]
Bridge=br0
# /etc/systemd/network/25-bridge-slave-2.network
[Match]
Name=sw1p3
[Network]
Bridge=br0
To make the changes take effect, start the systemd-networkd service:
$ systemctl start systemd-networkd
Assuming the service is enabled, the configuration will persist across reboots.
Since systemd version 242, systemd will set a persistent MAC
address on virtual interfaces such as bridges. Therefore, upon the
enslavement of an interface to the bridge, the bridge will no longer
inherit the interface's MAC address.
The driver requires that all the router interfaces share the same MSBs in their MAC. It will therefore veto the addition of an IP address on the bridge interface with the following error:
Error: mlxsw_spectrum: All router interface MAC addresses must have the same prefix.
To prevent systemd from changing the MAC address of interfaces,
MACAddressPolicy needs to be set to none.
# /etc/systemd/network/10-ignore.link
[Match]
OriginalName=*
[Link]
MACAddressPolicy=none
- man systemd-networkd
- man systemd.network
- man systemd.netdev