You are not logged in.

#1 2014-04-24 20:49:53

lorcap
Member
From: Italy
Registered: 2013-10-08
Posts: 4

systemd-networkd + resolvconf

The trick below stopped working with systemd 213.

Hi there,

I was trying to pass DHCP data from systemd-networkd to resolvconf instead of symlinking /run/systemd/network/resolv.conf to /resolv.conf.  And this is what I ended up with:

[Service]
ExecStartPost=/bin/sh -c '\
        for ((i=5; i; i--)); do\
                sleep 1;\
                grep -E --quiet --max-count 1 --invert-match "^(#|$)" /run/systemd/network/resolv.conf\
                && /usr/bin/resolvconf -a systemd < /run/systemd/network/resolv.conf\
                && exit 0;\
        done;\
        exit 1'
ExecStopPost=/usr/bin/resolvconf -d systemd

It works, but maybe someone came up with a better solution.  For example,

  1. I used systemd as interface for resolvconf.  Is this legal?  Should I use anything like eth0, is it possible to obtain it as a %-something?

  2. Is there a sleep with a resolution higher than 1 second? Pauses of 1 second are too long. 100-200ms would be enough, IMO.

Last edited by lorcap (2014-06-11 20:47:47)

Offline

#2 2014-04-28 23:35:37

rsmarples
Member
Registered: 2009-05-12
Posts: 287

Re: systemd-networkd + resolvconf

lorcap wrote:

Hi there,

I was trying to pass DHCP data from systemd-networkd to resolvconf instead of symlinking /run/systemd/network/resolv.conf to /resolv.conf.  And this is what I ended up with:

[Service]
ExecStartPost=/bin/sh -c '\
        for ((i=5; i; i--)); do\
                sleep 1;\
                grep -E --quiet --max-count 1 --invert-match "^(#|$)" /run/systemd/network/resolv.conf\
                && /usr/bin/resolvconf -a systemd < /run/systemd/network/resolv.conf\
                && exit 0;\
        done;\
        exit 1'
ExecStopPost=/usr/bin/resolvconf -d systemd

It works, but maybe someone came up with a better solution.  For example,

  1. I used systemd as interface for resolvconf.  Is this legal?  Should I use anything like eth0, is it possible to obtain it as a %-something?

  2. Is there a sleep with a resolution higher than 1 second? Pauses of 1 second are too long. 100-200ms would be enough, IMO.

  1. Yes it's legal.

  2. No, POSIX does not support higher resolutions. However, the bash shell does if you want to go that route

But this sounds awfully weird. Why is systemd adding resolv.conf information in the first place?

Offline

#3 2014-05-01 04:33:13

lorcap
Member
From: Italy
Registered: 2013-10-08
Posts: 4

Re: systemd-networkd + resolvconf

rsmarples wrote:

No, POSIX does not support higher resolutions. However, the bash shell does if you want to go that route

I search bash manual for "sleep" but I couldn't find anything.  Even 'help sleep' returns nothing.  How do you do that?

rsmarples wrote:

But this sounds awfully weird. Why is systemd adding resolv.conf information in the first place?

I guess you meant why systemd is not adding resolv.conf information.

I think it is by design.  At least, if I correctly understand the comment to the patch which added this feature.

Offline

#4 2014-05-01 08:17:23

rsmarples
Member
Registered: 2009-05-12
Posts: 287

Re: systemd-networkd + resolvconf

My bad, GNU sleep, not the shell built in.
http://man7.org/linux/man-pages/man1/sleep.1.html

No, I meant what I said. I don't understand what business systemd has writing to resolv.conf.
It's not a DHCP client, nor a network configurator.

Offline

#5 2014-05-01 15:12:48

branch
Member
Registered: 2014-03-16
Posts: 209

Re: systemd-networkd + resolvconf

rsmarples wrote:

No, I meant what I said. I don't understand what business systemd has writing to resolv.conf.
It's not a DHCP client, nor a network configurator.

systemd doesn't write to any resolve.conf unless a service file is written to make it do so. networkd is a network configurator, and so writes to /run/systemd/network/resolv.conf. If networkd is a system's only network configurator then it is sufficient to symlink /etc/resolve.conf to /run/systemd/network/resolv.conf. If another network configurator is used in conjunction with networkd then /run/systemd/network/resolv.conf must be merged into /etc/resolv.conf. The OP has implemented this merge by calling resolvconf from a systemd service file.

Offline

Board footer

Powered by FluxBB