You are not logged in.

#1 2019-08-10 10:24:41

pencuse
Member
From: Germany
Registered: 2008-05-12
Posts: 17

[SOLVED] systemd-networkd cannot create symlink /etc/resolv.conf

Problem Description

When starting systemd-networkd, its drop-in cannot create symlink /etc/resolv.conf due to file permissions and service aborts.

Setup
  • I am trying to set up wireless network connection WPA Supplicant + systemd-networkd.

  • OS: Arch Linux 20190801 fresh install, nothing installed. Only root user is available, i.e. all steps below run in root account.

Things done
  1. Create a WPA supplicant configuration file /etc/wpa_supplicant/wpa_supplicant-wlp2s0.conf.

  2. Create a systemd-networkd configuration file /etc/systemd/network/25-wireless.network.

  3. Create a systemd-networkd drop-in unit file /etc/systemd/system/systemd-networkd.d/resolv.conf which automates symbolic link /resolv.conf creation, as proposed by WonderWoofy in this topic:

    [Service]
    ExecStartPost=/usr/bin/ln -sf /run/systemd/network/resolv.conf /etc/resolv.conf
    ExecStopPost=/usr/bin/rm /etc/resolv.conf
    ExecStopPost=/usr/bin/touch /etc/resolv.conf 
  4. When systemd-networkd started following comes out:

    # systemctl start systemd-networkd 
    Job for systemd-networkd.service failed because the control process exited with error code.
    See "systemctl status systemd-networkd.service" and "journalctl -xe" for details.
  5. journalctl -xe says:

    Aug 10 08:38:12 host-arch systemd[1]: Starting Network Service...
    -- Subject: A start job for unit systemd-networkd.service has begun execution
    -- Defined-By: systemd
    -- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
    -- 
    -- A start job for unit systemd-networkd.service has begun execution.
    -- 
    -- The job identifier is 260.
    Aug 10 08:38:12 host-arch systemd-networkd[533]: wlp2s0: Gained IPv6LL
    Aug 10 08:38:12 host-arch systemd-networkd[533]: Enumeration completed
    Aug 10 08:38:12 host-arch ln[535]: /usr/bin/ln: failed to create symbolic link '/etc/resolv.conf': Read-only file system
    Aug 10 08:38:12 host-arch systemd[1]: systemd-networkd.service: Control process exited, code=exited, status=1/FAILURE
    -- Subject: Unit process exited
    -- Defined-By: systemd
    -- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
    -- 
    -- An ExecStartPost= process belonging to unit systemd-networkd.service has exited.
    -- 
    -- The process' exit code is 'exited' and its exit status is 1.
  6. EDIT: systemctl status systemd-networkd shows:

    ● systemd-networkd.service - Network Service
       Loaded: loaded (/usr/lib/systemd/system/systemd-networkd.service; disabled; vendor preset: enabled)
      Drop-In: /etc/systemd/system/systemd-networkd.service.d
               └─resolv.conf
       Active: failed (Result: exit-code) since Sat 2019-08-10 12:30:35 CEST; 20s ago
         Docs: man:systemd-networkd.service(8)
      Process: 498 ExecStart=/usr/lib/systemd/systemd-networkd (code=exited, status=0/SUCCESS)
      Process: 499 ExecStartPost=/usr/bin/ln -sf /run/systemd/network/resolv.conf /etc/resolv.conf (code=exited, status=1/FAILURE)
      Process: 501 ExecStopPost=/usr/bin/rm /etc/resolv.conf (code=exited, status=1/FAILURE)
     Main PID: 498 (code=exited, status=0/SUCCESS)
       Status: "Shutting down..."
    
    Aug 10 12:30:35 host-arch systemd[1]: systemd-networkd.service: Service has no hold-off time (RestartSec=0), scheduling restart.
    Aug 10 12:30:35 host-arch systemd[1]: systemd-networkd.service: Scheduled restart job, restart counter is at 5.
    Aug 10 12:30:35 host-arch systemd[1]: Stopped Network Service.
    Aug 10 12:30:35 host-arch systemd[1]: systemd-networkd.service: Start request repeated too quickly.
    Aug 10 12:30:35 host-arch systemd[1]: systemd-networkd.service: Failed with result 'exit-code'.
    Aug 10 12:30:35 host-arch systemd[1]: Failed to start Network Service.
  7. However as a root I am able to create a symlink, also check the attributes of the file.

    # lsattr /etc/resolv.conf
    -------------------- /etc/resolv.conf
    # ls -l /etc/resolv.conf
    -rw-r--r-- 1 root root 65 Aug 10 11:04 /etc/resolv.conf
    # ln -sf somefile /etc/resolv.conf
    # ls -l /etc/resolv.conf
    lrwxrwxrwx 1 root root 8 Aug 10 11:12 /etc/resolv.conf -> somefile

I have searched the web, forums, but nothing comparable found. I could not find in the systemd service manuals specific information about permissions. However, since systemd-networkd is not able to change this file, there must be some permission setting for systemd-networkd which needs to be configured so that it can update files.

What did miss here?
Thanks in advance.

Last edited by pencuse (2019-08-10 14:41:02)


Computer: Dell Latitude E7440 - CPU: Intel Core i7-4600 - Harddisk: PM851 256 GB SSD - RAM: 8 GB DDR3L - Graphics: Intel HD 4400 (integrated in the CPU)
Enabled at UEFI: Virtualization, TPM - SecureBoot disabled
OS: Lubuntu 19.04+Arch Linux

Offline

#2 2019-08-10 10:50:54

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [SOLVED] systemd-networkd cannot create symlink /etc/resolv.conf

The systemd-networkd is configured with ProtectSystem=strict, so it cannot write any files to /etc. I do not recommend to change that.

You don't need this symlink to be dynamic, just create it once and leave it there.

Last edited by progandy (2019-08-10 10:53:18)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#3 2019-08-10 10:51:05

Omar007
Member
Registered: 2015-04-09
Posts: 368

Re: [SOLVED] systemd-networkd cannot create symlink /etc/resolv.conf

As far as I'm aware the path you've currently defined (/run/systemd/network/resolv.conf) does not even exist. Maybe it all did work in 2014 but I can't verify that.

From what I can tell you want to set up some resolver. Assuming you want to stay in the systemd-* realm, you'd want to set up systemd-resolved to manage /etc/resolv.conf.
https://wiki.archlinux.org/index.php/Systemd-resolved

There are more options available though (and potentially better ones if you care about security features).

EDIT: regardless of the setup you choose (static or with a resolver), don't forget to remove the service override.

Last edited by Omar007 (2019-08-10 10:54:57)

Offline

#4 2019-08-10 10:58:02

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [SOLVED] systemd-networkd cannot create symlink /etc/resolv.conf

/run/systemd/network/resolv.conf exists if systemd-resolvd is running, but it is better to link to /run/systemd/resolve/stub-resolv.conf instead if you want to use systemd-resolved.

See the wiki article linked by Omar007 and the resolv.conf section in the systemd-resolved manpage.

Last edited by progandy (2019-08-10 11:05:08)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2019-08-10 11:01:55

Omar007
Member
Registered: 2015-04-09
Posts: 368

Re: [SOLVED] systemd-networkd cannot create symlink /etc/resolv.conf

progandy wrote:

/run/systemd/network/resolv.conf exists if systemd-resolvd is running

I think you're confused with /run/systemd/resolve/resolv.conf which would contain the servers received from the uplink when you use systemd-resolved.

Offline

#6 2019-08-10 11:04:47

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [SOLVED] systemd-networkd cannot create symlink /etc/resolv.conf

Right. I looked at that path twice and still couldn't see difference...


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#7 2019-08-10 14:40:15

pencuse
Member
From: Germany
Registered: 2008-05-12
Posts: 17

Re: [SOLVED] systemd-networkd cannot create symlink /etc/resolv.conf

progandy, Omar007, thank you very much! As you proposed, the fixes were:

  • delete the drop-in unit file of systemd-networkd (/etc/systemd/system/systemd-networkd.d/resolv.conf)

  • create a symbolic link from /run/systemd/resolve/stub-resolv.conf to /etc/resolv.conf (ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf)

  • start (and enable) the services systemd-resolved and systemd-networkd

  • service unit files in original state

All three services (2x systemd and WPA supplicant) are up and running, even after 2 reboots. Internet connection is up running:

PING spiegel.de (128.65.210.8) 56(84) bytes of data.
64 bytes from 128.65.210.8 (128.65.210.8): icmp_seq=1 ttl=57 time=29.7 ms
64 bytes from 128.65.210.8 (128.65.210.8): icmp_seq=2 ttl=57 time=29.10 ms
64 bytes from 128.65.210.8 (128.65.210.8): icmp_seq=3 ttl=57 time=39.0 ms
--- spiegel.de ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 5ms
rtt min/avg/max/mdev = 29.703/32.893/39.014/4.331 ms

For me, the most important is to get an internet access somehow, so that I can configure the system by additional tools. Afterwards I will take a look at other network configuration options.

I will edit subject of OP.

Last edited by pencuse (2019-08-10 14:43:24)


Computer: Dell Latitude E7440 - CPU: Intel Core i7-4600 - Harddisk: PM851 256 GB SSD - RAM: 8 GB DDR3L - Graphics: Intel HD 4400 (integrated in the CPU)
Enabled at UEFI: Virtualization, TPM - SecureBoot disabled
OS: Lubuntu 19.04+Arch Linux

Offline

Board footer

Powered by FluxBB