So, changing my wired eth0 interface to be managed solved this issue for me.
Changing ifupdown to managed=true in /etc/NetworkManager/NetworkManager.conf
[ifupdown]
managed=true
Then restart NetworkManager
sudo systemctl restart NetworkManager
After this it works flawlessly..
This was not 100%. I also applied theses changes to try and kill resolver
sudo service resolvconf disable-updates
sudo update-rc.d resolvconf disable
sudo service resolvconf stop
Big thanks to this blog post regarding the subject:
https://ohthehugemanatee.org/blog/2018/01/25/my-war-on-systemd-resolved/
Lets pray this works.. This whole systemd-resolve business is just so ugly.
In the configuration file for local network interface (a file matching the name pattern /etc/systemd/network/*.network
) we have to either specify we want to obtain local DNS server address from DHCP server using DHCP=
option:
[Network]
DHCP=yes
or specify its address explicitly using DNS=
option:
[Network]
DNS=10.0.0.1
In addition we need to specify (in the same section) local domains using Domains=
option
Domains=domainA.example domainB.example ~example
We specify local domains domainA.example domainB.example
to get the following behavior (from systemd-resolved.service, systemd-resolved man page):
Lookups for a hostname ending in one of the per-interface domains are
exclusively routed to the matching interfaces.
This way hostX.domainA.example
will be resolved exclusively by our local DNS server.
We specify with ~example
that all domains ending in example
are to be treated as route-only domains to get the following behavior (from description of this commit) :
DNS servers which have route-only domains should only be used for the
specified domains.
This way hostY.on.the.internet
will be resolved exclusively by our global, remote DNS server.
Note
Ideally, when using DHCP protocol, local domain names should be obtained from DHCP server instead of being specified explicitly in configuration file of network interface above. See UseDomains=
option. However there are still outstanding issues with this feature – see systemd-networkd DHCP search domains option issue.
We need to specify remote DNS server as our global, system-wide DNS server. We can do this in /etc/systemd/resolved.conf
file:
[Resolve]
DNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
Don't forget to reload configuration and to restart services:
$ sudo systemctl daemon-reload
$ sudo systemctl restart systemd-networkd
$ sudo systemctl restart systemd-resolved
Caution!
Above guarantees apply only when names are being resolved by systemd-resolved – see man page for nss-resolve, libnss_resolve.so.2 and man page for systemd-resolved.service, systemd-resolved.
See also:
References:
Best Answer
Adding an entry to
/etc/hosts
is supposed to work and in my tests it worked as expected. My tests are on Fedora Rawhide, with version systemd-239-9.git9f3aed1.fc30.x86_64, so that's a pretty recent snapshot of systemd, maybe older versions will not work the same as expected...Before adding the entry to
/etc/hosts
:1) resolvectl query:
2) ping:
3) curl:
After adding the entry, in which case
/etc/hosts
looks like this:Tests showed the blocking is working:
1) resolvectl query:
2) ping:
3) curl:
So the block seems to be working.
I expected this would work, since this was brought up recently in an issue filed against systemd. Issue #9718 talked about adding millions of entries to
/etc/hosts
, which has one usecase and that's blacklisting domains, such as here.Please note that there are quite a few moving parts here, so it's important to consider those while troubleshooting this.
My
/etc/systemd/resolved.conf
has no overridden configuration, all entries are commented out, network setup is using systemd-networkd with DHCP and no overrides either.Output of
resolvectl status
includes:Configuration of
/etc/resolv.conf
is using the stub resolver:And nsswitch.conf is configured to use nss-resolve(8) according to the recommendation from its man page:
If you still can't make it work, you might want to check these settings in your system and confirm they are all configured correctly. Or, at least, post your current configuration here (together with Linux distro and systemd version) to help diagnose why it might not be working for you.