1

I'm using wireguard client with the following PostUp script:

PostUp = systemd-resolve -i %i --set-dns=x.x.x.x --set-domain=~.

systemd-resolve did set the DNS setting correctly and 127.0.0.53 was able to resolve domain.

$ resolvectl status
Link 5 (wg1)
      Current Scopes: DNS
DefaultRoute setting: yes
       LLMNR setting: yes
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: yes
    DNSSEC supported: yes
  Current DNS Server: x.x.x.x
         DNS Servers: x.x.x.x
          DNS Domain: ~.

But the DNS setting reset after wake from suspend:

$ resolvectl status
Link 5 (wg1)
      Current Scopes: none
DefaultRoute setting: no
       LLMNR setting: yes
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: yes
    DNSSEC supported: yes

I found a similar question, but this is about making the config persists across suspend, not reboot. In my case, the DNS setting does persist across reboot.

I'm using Ubuntu's wireguard, not the ppa.

$ apt search wireguard
wireguard/eoan,eoan,now 0.0.20190913-1ubuntu1 all [installed]
wireguard-dkms/eoan,eoan,now 0.0.20190913-1ubuntu1 all [installed,automatic]
wireguard-tools/eoan,now 0.0.20190913-1ubuntu1 amd64 [installed,automatic]

Edit: Same issue with launchpad version.

wireguard/eoan,eoan,now 0.0.20191012-wg1~eoan all [installed]
wireguard-dkms/eoan,eoan,now 0.0.20191012-wg1~eoan all [installed,automatic]
wireguard-tools/eoan,now 0.0.20191012-wg1~eoan amd64 [installed,automatic]

I tried several workarounds, none of them worked.

  1. /etc/systemd/network/wireguard.network
[Match]
Name=wg1

[Network]
DNS=x.x.x.x
Domains=~.

While this approach did set the DNS for wireguard interface, systemd-resolved fallback to eth0's DNS after wake.

$ resolvectl status
Link 5 (wg1)
      Current Scopes: none
  Current DNS Server: x.x.x.x
         DNS Servers: x.x.x.x

Link 2 (eth0)
      Current Scopes: DNS
  Current DNS Server: y.y.y.y
         DNS Servers: y.y.y.y
  1. Run a script after wake from suspend, /lib/systemd/system-sleep/wireguard-dns
#!/bin/sh

case $1/$2 in
  pre/*)
    exit 0
    ;;
  post/*)
    # Place your post suspend (resume) commands here
    systemd-resolve -i wg1 --set-dns=x.x.x.x --set-domain=~.
    ;;
esac

This workaround didn't work, the DNS config still reset after wake. I did verify the script did get executed (I tested with echo "script executed" > /home/user/output, file was there with the text), but somehow it had no effect.

Similar script in /usr/lib/pm-utils/sleep.d only worked for a few seconds (after wake), then the config reset and fallback to eth0's DNS.

#!/bin/sh

case $1 in 
        thaw|resume)
                systemd-resolve -i wg1 --set-dns=x.x.x.x --set-domain=~.
        ;;
esac
  1. Tried another wake-from-suspend script, same result as no. 1.
#!/bin/sh

if [ "$1" = "pre" ] && [ "$2" = "suspend" ]; then
    wg-quick down wg1
elif [ "$1" = "post" ] && [ "$2" = "suspend" ]; then
    wg-quick up wg1
fi

Edit: Same issue on fresh install.

Edit: Also affects 19.04, tried on fresh install.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.