Skip to content

After connected to VPN, systemd-resolve still use ISP's DNS server( which was polluted because of regulation ) #6076

Closed

Description

@joshuafc

Submission type

  • Request for enhancement (RFE)

systemd version the issue has been seen with

systemd 232
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

Used distribution

Ubuntu 17.04 Linux version 4.10.0-21-generic (buildd@lgw01-12) (gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2) ) #23-Ubuntu SMP Fri Apr 28 16:14:22 UTC 2017

Because of the Internet regulation, ISP's DNS server can not resolve some domian correctly( for example www.google.com www.youtube.com ). Under normal conditions, we use vpn and set the vpn as default internet gateway when needed to access above website.
When I start to use Ubuntu 17.04, It is found that when connected to vpn, all internet package transfer through vpn except domain name resolve. Infact, VPN server had tell correct DNS server IP address through DHCP. But systemd-resolve still use ISP's polluted resolve.
At /etc/resolv.conf, I found that DNS resolve had be taken over by systemd-resolve. There can't find any easy way to tell systemd-resolve to use a specified DNS server, or disable any DNS server according " systemd-resolve --help ".
Willing to accept guidance to correct my use of systemd-resolve,
If you can, Please add some necessary feature to systemd-resolve to solve such problem,

In case of bug report: Expected behaviour you didn't see

…

In case of bug report: Unexpected behaviour you saw

…

In case of bug report: Steps to reproduce the problem

…

Activity

  1. poettering commented on Jun 13, 2017

    @poettering
    Member

    Hmm, not sure I follow. How exactly did you configure your DNS? What does "systemd-resolve --status" report about the DNS servers? Is /etc/resolv.conf a file or a symlink?

  2. added
    needs-reporter-feedback ❓
    on Jun 13, 2017
  3. joshuafc commented on Jun 20, 2017

    @joshuafc
    Author

    @poettering thanks for your reply.

    here is the information

    zhoub@ubuntu:\~$ ll /etc/resolv.conf 
    rwxrwxrwx 1 root root 29 Jun  6 09:35 /etc/resolv.conf -> ../run/resolvconf/resolv.conf
    zhoub@ubuntu:~$ cat /etc/resolv.conf 
    \# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
    \#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
    \# 127.0.0.53 is the systemd-resolved stub resolver.
    \# run "systemd-resolve --status" to see details about the actual nameservers.
    
    nameserver 127.0.0.53
    zhoub@ubuntu:~$ systemd-resolve --status
    Global
              DNSSEC NTA: 10.in-addr.arpa
                          16.172.in-addr.arpa
                          168.192.in-addr.arpa
                          17.172.in-addr.arpa
                          18.172.in-addr.arpa
                          19.172.in-addr.arpa
                          20.172.in-addr.arpa
                          21.172.in-addr.arpa
                          22.172.in-addr.arpa
                          23.172.in-addr.arpa
                          24.172.in-addr.arpa
                          25.172.in-addr.arpa
                          26.172.in-addr.arpa
                          27.172.in-addr.arpa
                          28.172.in-addr.arpa
                          29.172.in-addr.arpa
                          30.172.in-addr.arpa
                          31.172.in-addr.arpa
                          corp
                          d.f.ip6.arpa
                          home
                          internal
                          intranet
                          lan
                          local
                          private
                          test
    
    Link 6 (ppp0)
          Current Scopes: none
           LLMNR setting: yes
    MulticastDNS setting: no
          DNSSEC setting: allow-downgrade
        DNSSEC supported: yes
    
    Link 2 (ens33)
          Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
           LLMNR setting: yes
    MulticastDNS setting: no
          DNSSEC setting: allow-downgrade
        DNSSEC supported: no
             DNS Servers: 192.168.83.2
              DNS Domain: localdomain
    zhoub@ubuntu:~$ ping www.google.com
    PING www.google.com (93.46.8.89) 56(84) bytes of data.
    ^C
    --- www.google.com ping statistics ---
    106 packets transmitted, 0 received, 100% packet loss, time 107507ms
    

    ping failed, 93.46.8.89 is incorrect , ISP's DNS server resolve it to 93.46.8.89 because of Internet regulation. VPN's DNS Server resolve it to 172.217.26.36, which can ping successfully.

    screenshot2
    screenshot
    screenshot1

  4. aigarius commented on Sep 21, 2017

    @aigarius

    Can confirm the same effect with a OpenVPN connection.

    Link 8 (tun0)
          Current Scopes: DNS
           LLMNR setting: yes
    MulticastDNS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
             DNS Servers: 172.20.0.50
                          172.20.0.14
    
    Link 3 (wlan0)
          Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
           LLMNR setting: yes
    MulticastDNS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
             DNS Servers: 192.168.192.1
              DNS Domain: net
    

    Running "systemd-resolve internal.name.local" fails to find it (it only tries the 192.* DNS server), running "systemd-resolve -i tun0 internal.name.local" resolves the name correctly (via 172.* DNS server), but no applications actually supply that interface, naturally.

    Systemd version 232
    Ubuntu 17.04

    Currently I have to workaround this by overwriting the /etc/resolv.conf file each time I connect to the VPN, but even that now stops working as some apps use the systemd-resolv directly if it is available.

    Alternative solution that worked for me is using a patched version of NetworkManager from https://bugs.launchpad.net/network-manager/+bug/1624317 that forces using the VPN DNS server by adding a "DNS Domain: ~." declaration to the tun0 section of systemd-resolve

  5. mikken commented on Oct 9, 2017

    @mikken

    You (joshuafc and aigarius) need to do 2 things:

    1. Make sure that DNS servers obtained from OpenVPN are used by systemd-resolved. You can do it with this little script: https://github.com/jonathanio/update-systemd-resolved
    2. While OpenVPN is connected, block (reject with iptables or nftables) all requests that systemd-resolved makes to local DNS server
  6. mikken commented on Oct 9, 2017

    @mikken

    aigarius, for you the domain .local should be configured as "routing" domain on this link (tun0).

  7. PureRumble commented on Oct 29, 2017

    @PureRumble

    @mikken, that script you're telling us to use is 400 lines long. What does it do? Any bugs? Is it safe or does it expose our systems to vulnerabilities? Will it break something else? Why do we need a 400 lines long script (and then to do even more stuff) to achieve something as essential as getting DNS lookups to go through the VPN connection?

    Nearly every time someone connects to a VPN service the user's expected system behaviour is that the VPN service's DNS servers should be used and all traffic should go through the VPN connection; this is especially true for novice users. This should therefore be the default behaviour.

    But not only is this not the default behavior, there also isn't some easy way to make systemd-resolved to work as desired (e.g. you have to use 400 lines long scripts, block packets to your ISP's DNS server at the IP-level, etc).

    systemd-resolved is a "system service that provides network name resolution". It is beyond essential that a system that "provides network name resolution" should be able to with little effort to be made to route DNS requests through a VPN connection. Also, it's default behavior out-of-the-box should comply with the most common use cases (e.g. user connects to a VPN service ==> all data goes through VPN connection).

  8. flo-wer commented on Oct 29, 2017

    @flo-wer

    See #7182

  9. snabb commented on Oct 29, 2017

    @snabb

    My current workaround is to do the following tricks every time I start my workplace VPN:

    1. Find out the link number (a.k.a. interface index) of the ISP interface: systemd-resolve --status or ip l.
    2. Connect the VPN.
    3. Remove DNS settings from the ISP interface (using the link number from step 1) by sending a D-Bus command to systemd-resolved. This is an example using link number 2: sudo busctl call org.freedesktop.resolve1 /org/freedesktop/resolve1 org.freedesktop.resolve1.Manager SetLinkDNS 'ia(iay)' 2 0
    4. Inspect with systemd-resolve --status to ensure that only the correct DNS servers are there.

    Apparently there isn't any simple cli tool for managing systemd-resolved's settings. That busctl command isn't very user-friendly. :)

  10. poettering commented on Dec 8, 2017

    @poettering
    Member

    So, resolved is actually doing the right thing here, given the configuration it was given. @joshuafc, resolved only knows the DNS server 192.168.83.2 in your setup, but you want it to know 208.67.222.222 and 8.8.8.8, right? If so, this information needs to be made available to resolved, and the ppp scripts (given that you are using ppp/pptp) need to push it into resolved, which i think ubuntu updated the "resolvconf" package to do. But that's really outside of the scope of upstream resolved. @nox, can you help? is there some ppp/pptp hookup missing for resolved in ubuntu?

  11. poettering commented on Dec 8, 2017

    @poettering
    Member

    @snabb #7576 adds the requested "simple cli" functionality to systemd-resolve.

  12. added and removed
    needs-reporter-feedback ❓
    on Dec 8, 2017
  13. jetsaredim commented on Jan 5, 2018

    @jetsaredim

    @poettering I'm confused by your most recent comment. If you review the contents of the most recent comment by @aigarius it shows that resolved does in fact have the DNS server addresses. He's just using google.com as an example to show the geo-located difference between his native connection and the vpn connection.

    I came to this bug because I have a similar situation and basically the exact same symptoms as described in @aigarius' most recent comment with an openconnect vpn configuration. It's clear from the output that systemd-resolved has the DNS server info for the DNS servers inside the VPN, but it's not updating the DNS cache to bring in the new DNS servers and thus having trouble resolving things inside the private VPN network that should resolve easily. And in fact do resolve easily if you point relevant commands at the correct interface/DNS server.

    A simple restart of systemd-resolved upon vpn connect/disconnect seems to fix the problem, but alas it really shouldn't be needed. Systemd-resolved should just be flushing the cache when a new DNS server is added.

  14. 95 remaining items

  15. zerkms commented on Nov 14, 2020

    @zerkms
    Contributor

    @sliddjur I use ipsec, there is no dedicated interface in my implementation: all traffic flows through one and the only physical interface.

  16. yuqian90 commented on Nov 18, 2020

    @yuqian90

    This issue is closed, but when I tried to use OpenVPN 2.4.7 on Ubuntu 20.04, this issue still causes DNS leaks. After some troubleshooting, I realized that I had to do all of the following:

    1. Install openvpn-systemd-resolved
    sudo apt-get install openvpn-systemd-resolved
    
    1. Add these lines to the .ovpn config. This sets the "DNS Domain" of the VPN interface tun0 to ~.
    script-security 2
    up /etc/openvpn/update-systemd-resolved
    up-restart
    down /etc/openvpn/update-systemd-resolved
    down-pre
    dhcp-option DOMAIN-ROUTE .
    
    1. After starting openvpn, I still had to do one more step, which is to remove the existing ~. from my default network interface (eno1 in my case). Otherwise DNS requests go to both tun0 and eno1 and still causes DNS leaks. This is the command:
    sudo systemd-resolve -i eno1 --set-domain lan
    

    Only after all three steps, openvpn finally stops leaking DNS. In systemd-resolve --status, this is what I now see. Without Step 3 above, the DNS Domain of eno1 is set to ~. and lan and thus still leaks DNS.

    $ systemd-resolve --status
    Global
           LLMNR setting: no
    MulticastDNS setting: no
      DNSOverTLS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
              DNS Domain: lan
    ...
    Link 8 (tun0)
          Current Scopes: DNS
    DefaultRoute setting: yes
           LLMNR setting: yes
    MulticastDNS setting: no
      DNSOverTLS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
      Current DNS Server: 1.1.1.1
             DNS Servers: 1.1.1.1
                          8.8.8.8
              DNS Domain: ~.
    
    ...
    
    Link 2 (eno1)
          Current Scopes: DNS
    DefaultRoute setting: yes
           LLMNR setting: yes
    MulticastDNS setting: no
      DNSOverTLS setting: no
          DNSSEC setting: no
        DNSSEC supported: no
      Current DNS Server: 192.168.X.X
             DNS Servers: 192.168.X.X
              DNS Domain: lan
    

    This is such a pain to do something simple. I want to point out that none of these were needed before systemd-resolved was introduced. Is there any plans to fix this?

  17. mcatanzaro commented on Nov 18, 2020

    @mcatanzaro
    Contributor

    This is such a pain to do something simple. I want to point out that none of these were needed before systemd-resolved was introduced. Is there any plans to fix this?

    No, it would need to be fixed by the openvpn developers, not by systemd-resolved. systemd-resolved only sends your DNS exactly where you tell it to, so there is nothing to fix. If you don't tell it what you want, it cannot do what you want.

    Your post is good documentation of how to manually tell systemd-resolved where your DNS is intended to go if you want to manually configure openvpn. Alternatively, if you are a desktop user, you could use NetworkManager-openvpn, which would take care of all of this for you automatically.

  18. yuqian90 commented on Nov 19, 2020

    @yuqian90

    This is such a pain to do something simple. I want to point out that none of these were needed before systemd-resolved was introduced. Is there any plans to fix this?

    No, it would need to be fixed by the openvpn developers, not by systemd-resolved. systemd-resolved only sends your DNS exactly where you tell it to, so there is nothing to fix. If you don't tell it what you want, it cannot do what you want.

    Your post is good documentation of how to manually tell systemd-resolved where your DNS is intended to go if you want to manually configure openvpn. Alternatively, if you are a desktop user, you could use NetworkManager-openvpn, which would take care of all of this for you automatically.

    Thanks. Let me try to find out if OpenVPN is fixing this.

  19. yuqian90 commented on Nov 20, 2020

    @yuqian90

    This is such a pain to do something simple. I want to point out that none of these were needed before systemd-resolved was introduced. Is there any plans to fix this?

    No, it would need to be fixed by the openvpn developers, not by systemd-resolved. systemd-resolved only sends your DNS exactly where you tell it to, so there is nothing to fix. If you don't tell it what you want, it cannot do what you want.

    Your post is good documentation of how to manually tell systemd-resolved where your DNS is intended to go if you want to manually configure openvpn. Alternatively, if you are a desktop user, you could use NetworkManager-openvpn, which would take care of all of this for you automatically.

    Hi @mcatanzaro one thing I want to point out is that, OpenVPN is not the only VPN client experiencing this issue. Others such as FortiClient have the same problem. Is it right to say that multiple VPN clients are broken and the issue is caused by those VPN clients themselves and not by systemd-resolved?

  20. poettering commented on Nov 20, 2020

    @poettering
    Member

    I put together some docs in #17678 that explain in detail what VPN should do to get the right config into systemd-resolved. PTAL.

  21. mcatanzaro commented on Nov 20, 2020

    @mcatanzaro
    Contributor

    Hi @mcatanzaro one thing I want to point out is that, OpenVPN is not the only VPN client experiencing this issue. Others such as FortiClient have the same problem. Is it right to say that multiple VPN clients are broken and the issue is caused by those VPN clients themselves and not by systemd-resolved?

    I'm surprised this is still a problem in 2020, since systemd-resolved has been default in Ubuntu for four years now, but yes, every VPN client that does not know how to configure systemd-resolved is going to be broken. Thanks for documenting how to do this, Lennart!

  22. AndrewVos commented on Apr 9, 2021

    @AndrewVos

    Wow, so I've just found this and have been wondering why I've had so many problems with ivpn. Time to go back to nordvpn.

  23. lestofante commented on Jan 15, 2023

    @lestofante

    I put together some docs in #17678 that explain in detail what VPN should do to get the right config into systemd-resolved. PTAL.

    Something is not working properly AFAIK,
    I follow the guide and issued the privacy suggested command, correct DNS ip is used but on the interface "end0" instead of the "tun0"; this happen only if the DNS server has the same ip as the VPN server, otherwise it seems to work correctly

    resolvectl domain tun0 '~.'
    resolvectl default-route tun0 true
    resolvectl dns tun0 192.216.219.147
    

    systemd-resolve --status

    Global
               Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
        resolv.conf mode: uplink
    Fallback DNS Servers: 1.1.1.1#cloudflare-dns.com 9.9.9.9#dns.quad9.net 8.8.8.8#dns.google 2606:4700:4700::1111#cloudflare-dns.com 2620:fe::9#dns.quad9.net 2001:4860:4860::8888#dns.google
    
    Link 2 (end0)
        Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
             Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
    Current DNS Server: 127.0.0.1
           DNS Servers: 127.0.0.1
    
    Link 19 (tun0)
        Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
             Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
    Current DNS Server: 195.216.219.147
           DNS Servers: 195.216.219.147
            DNS Domain: ~.
    

    but making a dns request (in this case a simple ping www.google.com) causes:

    [nftables][end0] DNS outbound Denied: IN= OUT=end0 SRC=192.168.0.3 DST=195.216.219.147 LEN=65 TOS=0x00 PREC=0x00 TTL=64 ID=50728 DF PROTO=UDP SPT=40224 DPT=53 LEN=45
    
    • the request is on end0, while it should be on tun0.
    • ping hangs as there is no answer from the DNS, so i dont think any parallel request is sent to tun0
    • setting the dns server to 8.8.8.8 or anything that is not the VPN's ip, seems to fix the issue

    As we talk about privacy setup, and as DNS request are not encrypted, letting them go to the VPN server without passing trough the tun0 is pretty much as bad as requesting to the ISP, as they are easy to intercept from the ISP.
    Also may be problematic in buisness setup, where the dns server may be listening only to request from the LAN rather than be accessible from the internet

    also i find very strange this different behavior based on the destination ip, am i triggering some edge case?

  24. tobiasbrunner commented on Jan 16, 2023

    @tobiasbrunner

    this happen only if the DNS server has the same ip as the VPN server

    To avoid routing the VPN traffic itself via TUN device, some route-based VPNs install a bypass route via physical interface for the VPN server's IP address. You might want to assign a second (maybe private) IP address to the VPN server that you use as DNS server address.

  25. lestofante commented on Jan 16, 2023

    @lestofante

    To avoid routing the VPN traffic itself via TUN device, some route-based VPNs install a bypass route via physical interface for the VPN server's IP address. You might want to assign a second (maybe private) IP address to the VPN server that you use as DNS server address.

    ok, this make a lot of sense and i guess a simple routing table cannot handle my case as it does not know the protocol, or at least the destination port.
    As i dont have access to server configuration, i guess my only solution is to make sure to use a different DNS server or do some iptables magic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions