The /etc/systemd/network/*.network files are used for configuring network interfaces with systemd-networkd, a system service in systemd that manages network configurations. These .network files define how network interfaces should behave, including network addresses, routes, and other networking-related settings.
Overview of /etc/systemd/network/*.network files
These configuration files are typically stored in the /etc/systemd/network/ directory, and each file typically corresponds to a network interface or a specific configuration group. The .network files allow administrators to configure various networking options for both Ethernet and Wi-Fi interfaces, such as IP addressing, routes, and DNS settings.
Basic Structure of a .network File
A .network file typically consists of multiple sections that define different aspects of the network interface.
This section provides specific DHCP client settings. It is only relevant when DHCP=yes in the [Network] section.
Common keys in this section:
ClientIdentifier: The identifier used by the DHCP client (usually MAC address or a custom identifier).
Hostname: The hostname assigned by DHCP.
UseDNS: Whether to use DNS information provided by DHCP.
Example:
[DHCP]ClientIdentifier=mac
[Link]
This section provides settings that control the interface link properties.
Common keys in this section:
MTUBytes: Set the Maximum Transmission Unit (MTU).
WakeOnLan: Enable or disable Wake-on-LAN.
Example:
[Link]MTUBytes=1500
[VLAN]
Used to configure VLAN interfaces.
Common keys in this section:
VLANId: The VLAN ID for this interface.
Example:
[VLAN]VLANId=10
Example .network File Configurations
Example 1: Using DHCP for Network Configuration
This configuration automatically assigns an IP address to the enp0s3 interface using DHCP.
Example 2: Static IP Configuration
This configuration assigns a static IP address 192.168.1.100/24 to enp0s3, with a gateway at 192.168.1.1 and a DNS server at 8.8.8.8.
Example 3: Using Static IP with Multiple Addresses
This configuration assigns two IP addresses to the interface enp0s3, 192.168.1.100/24 and 192.168.2.100/24, and uses the same gateway and DNS.
Example 4: VLAN Configuration
This configuration creates a VLAN interface with the ID 10 on the enp0s3 interface and assigns it a static IP address.
File Naming Convention
Network configuration files in /etc/systemd/network/ typically follow a naming convention like XX-<interface>.network, where XX is a numeric prefix to control the order in which configurations are applied, and <interface> is the network interface name. Files with more specific names will override more generic configurations.
For example:
10-eth0.network
20-wlan0.network
Applying Changes
To apply the changes made to .network files, you need to restart the systemd-networkd service:
Alternatively, to reload the configurations without fully restarting:
Conclusion
The .network files under /etc/systemd/network/ are used to configure various aspects of network interfaces, such as IP addressing, DNS, and routes, using systemd-networkd. These files are an alternative to traditional network management tools like ifup/ifdown or NetworkManager, and are especially useful in server environments or minimal installations where you prefer direct control over network configurations.