Network Management With Systemd

Jump to: navigation, search

Introduction

Systemd tools for networkd and resolved are used to configure network services.

Equipment

FRITZ!Box 7360

This router provides a DHCP and a DNS server: Handbuch FRITZ!Box 7360 (pdf)

FRITZ!Box 7530 AX

This model replaced the FRITZ!Box 7360: Handbuch FRITZ!Box 7530 AX (pdf). Its DNS Server has issues with IPv6. Enabling avahi-dnsconfd on the clients fixes them.

Desktop Computer

6700k:~ # inxi -zSMCDG
System:
  Kernel: 5.19.8-1-default arch: x86_64 bits: 64 Console: pty pts/3 Distro: openSUSE Tumbleweed
    20220922
Machine:
  Type: Desktop Mobo: ASRock model: Z170 Pro4S serial: <filter> UEFI: American Megatrends
    v: P7.50 date: 01/23/2018
CPU:
  Info: quad core model: Intel Core i7-6700K bits: 64 type: MT MCP cache: L2: 1024 KiB
  Speed (MHz): avg: 3600 min/max: 800/4200 cores: 1: 4000 2: 4000 3: 4000 4: 800 5: 4000
    6: 4000 7: 4000 8: 4000
Graphics:
  Device-1: Intel HD Graphics 530 driver: i915 v: kernel
  Display: x11 server: X.org v: 1.21.1.4 with: Xwayland v: 22.1.3 driver: X:
    loaded: modesetting unloaded: fbdev,vesa gpu: i915 tty: 238x52 resolution: 1920x1200
  Message: GL data unavailable in console for root.
Drives:
  Local Storage: total: 698.65 GiB used: 7.72 GiB (1.1%)
  ID-1: /dev/sda vendor: Samsung model: SSD 850 EVO 500GB size: 465.76 GiB
  ID-2: /dev/sdb vendor: Crucial model: CT250MX500SSD1 size: 232.89 GiB
6700k:~ # 


Installation

Check Version installed:

6700k:~ # zypper search --installed-only --details systemd-network
Loading repository data...
Reading installed packages...

S  | Name            | Type    | Version   | Arch   | Repository
---+-----------------+---------+-----------+--------+-----------------------
i+ | systemd-network | package | 251.4-3.1 | x86_64 | Haupt-Repository (OSS)
6700k:~ # 


Disable Network Services

6700k:~ # systemctl disable --now NetworkManager
6700k:~ # systemctl list-unit-files NetworkManager*
UNIT FILE                          STATE    PRESET  
NetworkManager-dispatcher.service  disabled disabled
NetworkManager-wait-online.service disabled disabled
NetworkManager.service             disabled disabled

3 unit files listed.
6700k:~ # 

Disable Changes To DNS Through Netconfig

Yast2 sysconfig may be used. Verify:

6700k:~ # grep NETCONFIG_DNS_POLICY /etc/sysconfig/network/config
NETCONFIG_DNS_POLICY=""
6700k:~ # 

Configure Links

Create a file with the following content (name must end with '.network'):

6700k:~ # cat /etc/systemd/network/wireless.network 
[Match]
Name=w* # wireless link

[Network]
DHCP=yes
Domains=fritz.box # replace by domain of local network
6700k:~ # 

 

Enable Network Service

3400G:~ # systemctl enable --now systemd-networkd 
3400G:~ # 

Query the status of network links

6700k:~ # networkctl 
IDX LINK      TYPE     OPERATIONAL SETUP     
  1 lo        loopback carrier     unmanaged
  2 enp0s31f6 ether    off         unmanaged
  3 wlp3s0    wlan     routable    configured

3 links listed.
6700k:~ # 

Enable Network Name Resolution

Resolve domain names, IPV4 and IPv6 addresses, DNS resource records, and services; introspect and reconfigure the DNS resolver

Check current setting of /etc/resolve.conf:

erlangen:~ # ll /etc/resolv.conf
lrwxrwxrwx 1 root root 30 Nov 27 07:54 /etc/resolv.conf -> /var/run/netconfig/resolv.conf
erlangen:~ # 

Save path and contents of target file (handy in case of undoing the changes).

Make sure /etc/resolve.conf is managed by resolved:

3400G:~ # ln -sf /run/systemd/resolve/resolv.conf /etc/
3400G:~ # systemctl enable --now systemd-resolved
3400G:~ # 

6700k:~ # cat /etc/resolv.conf 
# This is /run/systemd/resolve/resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 192.168.178.1
nameserver fd00::a96:d7ff:fee2:d6cf
search fritz.box
6700k:~ # 

Query The Status Of Resolver

6700k:~ # resolvectl 
Global
       Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: uplink

Link 2 (enp0s31f6)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

Link 3 (wlp3s0)
Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
     Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
   DNS Servers: 192.168.178.1 fd00::a96:d7ff:fee2:d6cf
    DNS Domain: fritz.box
6700k:~ # 



Wpa Supplicant

Wi-Fi Protected Access client and IEEE 802.1X supplicant

Some editing required. Run "systemctl edit --full wpa_supplicant@wlp3s0.service".

6700k:~ # systemctl cat wpa_supplicant@wlp3s0.service 
# /etc/systemd/system/wpa_supplicant@wlp3s0.service
[Unit]
Description=WPA Supplicant daemon (interface %i)
After=dbus.service network.target
Requires=sys-subsystem-net-devices-%i.device # Changed %I to lowercase %i
After=sys-subsystem-net-devices-%i.device    # Changed %I to lowercase %i

[Service]
Type=dbus
BusName=fi.w1.wpa_supplicant1
ExecStart=/usr/sbin/wpa_supplicant -i%i -c /etc/wpa_supplicant/wpa_supplicant.conf -u -t -f /var/log/wpa_supplicant.log

[Install]
WantedBy=multi-user.target
6700k:~ # 

Enable the service:

6700k:~ # systemctl enable --now wpa_supplicant@wlp3s0
6700k:~ # systemctl status wpa_supplicant@wlp3s0
● wpa_supplicant@wlp3s0.service - WPA Supplicant daemon (interface wlp3s0)
     Loaded: loaded (/etc/systemd/system/wpa_supplicant@wlp3s0.service; enabled; preset: disabled)
     Active: active (running) since Sun 2022-09-25 12:05:51 CEST; 5min ago
   Main PID: 9026 (wpa_supplicant)
      Tasks: 1 (limit: 4915)
        CPU: 64ms
     CGroup: /system.slice/system-wpa_supplicant.slice/wpa_supplicant@wlp3s0.service
             └─9026 /usr/sbin/wpa_supplicant -iwlp3s0 -c /etc/wpa_supplicant/wpa_supplicant.conf -u -t -f /var/log/wpa_supplicant.log

Sep 25 12:05:51 6700k systemd[1]: Starting WPA Supplicant daemon (interface wlp3s0)...
Sep 25 12:05:51 6700k systemd[1]: Started WPA Supplicant daemon (interface wlp3s0).
Sep 25 12:10:47 6700k systemd[1]: Started WPA Supplicant daemon (interface wlp3s0).
Sep 25 12:11:30 6700k systemd[1]: Started WPA Supplicant daemon (interface wlp3s0).
6700k:~ # 


Troubleshooting

FRITZ!Box

Resetting both the DHCP and the DNS server helps in clearing leases and cached information

Networkd/Resolved

Enable debugging by uncommenting:

3400G:~ # cat /etc/systemd/system/systemd-networkd.service.d/override.conf
[Service]
#Environment=SYSTEMD_LOG_LEVEL=debug
3400G:~ # 

Undoing Changes

See: I think I broke my internet