[systemd-devel] systemd-networkd: How to configure network with environment variables?
Nicholas Labich
nick at labich.org
Fri Apr 23 13:09:37 UTC 2021
On Fri, Apr 23, 2021 at 10:00:32 +0200 Lennart Poettering
<lennart at poettering.net> wrote:
> On Fr, 23.04.21 08:17, Paul Menzel (pmenzel+systemd-devel at molgen.mpg.de) wrote:
>
> > Dear systemd folks,
> >
> >
> > Due to historical reasons, in our environment we have a configuration file
> > with the network device name and the to be assigned IP address:
> >
> > $ more /etc/local/mxhost.conf
> > MX_NETDEV=net02
> > MX_IPADDR=141.14.18.X
> >
> > Then a custom service unit `network.service` [1] configures the network with
> > the configuration file as environment file.
> >
> > [Unit]
> > Description=Network Connectivity
> > DefaultDependencies=no
> >
> > [Service]
> > EnvironmentFile=/etc/local/mxhost.conf
> > Type=oneshot
> > RemainAfterExit=yes
> > ExecStart=/usr/sbin/mxnetctl start
> > ExecStart=/sbin/ip addr add ${MX_IPADDR}/20 broadcast 141.14.31.255 dev
> > ${MX_NETDEV}
> > ExecStart=/sbin/ip link set up dev ${MX_NETDEV}
> > ExecStart=/sbin/ip route add default via 141.14.16.X
> > ExecStop=/sbin/ip addr del ${MX_IPADDR}/20 dev ${MX_NETDEV}
> > StandardOutput=syslog
> >
> > [Install]
> > WantedBy=network.target
> >
> > Wanting to use systemd-network but keeping local device configuration in
> > `/etc/local` is there an easy way? systemd.network(5) does not say anything
> > about, that environment variables could be used.
> >
> > If that does not work, do you have another suggestion? Possible, but not
> > nice, solutions, I came up with:
>
> No, networkd has no support for that.
>
> > 1. Use a generator to create .network files from `/etc/local/mxhost.conf`.
>
> Yes, that should be really easy to implement, i.e. just write a small
> shell script, that sources that config files and outputs the .network
> file into /run somewhere via a here document, and then run this script
> during boot, and order it before networkd, so that the conversion is
> completed on each boot, before networkd is run.
>
> Lennart
This would be a nice feature in networkd. Another use case would be to
supply a WireGuard PrivateKeyFile via the CREDENTIALS_DIRECTORY from a
container host. I'm not sure that this can be implemented with a
generator (please correct me if I'm wrong).
More information about the systemd-devel
mailing list