19

I know there are other posts here asking this, but those suggestions do not help, the configuration keeps changing and I simply cannot get my own changes to persist.

I have the Google 8.8.8.8 and 8.8.4.4 servers in my Network Manager configuration in the GUI, and

systemd-resolv --status returns

Link 2 (enp38s0f1)
      Current Scopes: DNS    
DefaultRoute setting: yes    
       LLMNR setting: yes    
MulticastDNS setting: no     
  DNSOverTLS setting: no     
      DNSSEC setting: no     
    DNSSEC supported: no     
  Current DNS Server: 8.8.8.8
         DNS Servers: 8.8.8.8
                      8.8.4.4
          DNS Domain: ~.   

Nevertheless, dig google.com shows

;; Query time: 0 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Mon Oct 05 11:08:26 EDT 2020
;; MSG SIZE  rcvd: 83

so my default route 192.168.1.1 as DNS. Furthermore, /etc/resolv.conf is a symlink to /run/systemd/resolve/resolv.conf, which in turn reads

# Generated by dhcpcd from enp38s0f1.dhcp, wlp0s20f3.dhcp
# /etc/resolv.conf.head can replace this line
domain fios-router.home
nameserver 192.168.1.1
# /etc/resolv.conf.tail can replace this line

The only enp38s0f1.dhcp file on this system (I've searched /) is /run/dhcpcd/resolv.conf/enp38s0f1.dhcp, which reads

# Generated by dhcpcd from enp38s0f1.dhcp
domain fios-router.home
search fios-router.home
nameserver 192.168.1.1

I have tried to write in other nameservers there, but they do not persist. In the past I've made the changes persistent by making the file immutable with chattr +i, but

lsattr /run/dhcpcd/resolv.conf/enp38s0f1.dhcp

returns

lsattr: Inappropriate ioctl for device While reading flags on /run/dhcpcd/resolv.conf/enp38s0f1.dhcp

so that attribute is not available here. And besides, I shouldn't have to make the file immutable anyway: there should presumably be some way I can control the DNS server..


Edit:

In response to comments below:

$ dpkg -l *dnsmasq*
---
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name             Version         Architecture Description
+++-================-===============-============-============================================
un  dnsmasq          <none>          <none>       (no description available)
ii  dnsmasq-base     2.80-1.1ubuntu1 amd64        Small caching DNS proxy and DHCP/TFTP server
un  dnsmasq-base-lua <none>          <none>       (no description available)
grobber
  • 313
  • 1
  • 3
  • 9
  • Seems like you are asking the wrong question. A better question would be "How can I troubleshoot why my configuration does not persist across a reboot?" – user535733 Oct 05 '20 at 15:37
  • Your setup actually looks ok. However, the /etc/resolv.conf symlink **might** be wrong. Edit your question and show me `cat /run/resolvconf/resolv.conf`, and `dpkg -l *dnsmasq*`. – heynnema Oct 05 '20 at 15:42
  • `cat: /run/resolvconf/resolv.conf: No such file or directory` – grobber Oct 05 '20 at 15:42
  • `systemd-resolv --status` correctly shows your desired DNS servers. What/where are you seeing a problem? – heynnema Oct 05 '20 at 15:45
  • Is DNS Automatic disabled in your NM GUI? – heynnema Oct 05 '20 at 15:47
  • Re: the problem: as per the original post, `dig google.com` shows `192.168.1.1` as the server rather than the desired `8.8.8.8`. And I don't see a `DNS Automatic`; I see `DNS 8.8.8.8 8.8.4.4` – grobber Oct 05 '20 at 15:51
  • Right above `DNS 8.8.8.8 8.8.4.4` is a slide switch that says "Automatic". – heynnema Oct 05 '20 at 15:54

2 Answers2

15

If your current DNS server is still your router (i.e. 192.168.1.1), although you have declared the desired nameservers in /etc/netplan/[network-mager].yaml or via the GUI of NetworkManager, there are at least two solutions to try:

  1. You may configure these settings using the already mentioned GUI:

    a) Choose a connection (from the Wired or Wireless tab) and click Edit. b) Click on the IPv4 Settings tab c) Choose 'Automatic (DHCP) addresses only' instead of just 'Automatic (DHCP)'. d) Enter the DNS servers in the “DNS servers” field, separated by spaces (e.g. 208.67.222.222 for OpenDNS). e) Click “Apply.”

Please, note that 'Automatic (DHCP) addresses only' means that the network you are connecting to uses a DHCP server to assign IP addresses but you want to assign DNS servers manually.

  1. or, if your DNS settigs are messed up by multiple programs updating it, you can use resolvconf:
sudo apt install resolvconf 
sudo systemctl enable --now resolvconf.service

then, edit /etc/resolvconf/resolv.conf.d/head and insert your desired nameservers as:

nameserver 8.8.8.8 
nameserver 8.8.4.4

Finally, to update /etc/resolv.conf run:

sudo resolvconf -u
giulianopz
  • 186
  • 2
  • 8
  • `apt install` doesn't work if you're without a working DNS. `echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf` changes it temporarily to CloudFlare DNS. I used it before applying this answer as a permanent fix. – Bob Ortiz Oct 23 '21 at 21:05
0

I believe I know how to resolve this. dhcpcd has a --nohook flag that instructs it to leave certain parts of your configuration alone. From my dhcpcd(8) man page:

-C, --nohook script
    Don't run this hook script. Matches full name, or prefixed with 2 numbers optionally ending with .sh.

    So to stop dhcpcd from touching your DNS settings you would do:-
    dhcpcd -C resolv.conf eth0 

So I altered my /lib/systemd/system/dhcpcd.service, changing the line

ExecStart=/usr/sbin/dhcpcd

to

ExecStart=/usr/sbin/dhcpcd -C /etc/resolv.conf

Afterwards, the nameservers 8.8.8.8 and 8.8.4.4 in /etc/resolv.conf survive the reboot.

grobber
  • 313
  • 1
  • 3
  • 9
  • Did you check the DNS Automatic setting that we were discussing? – heynnema Oct 05 '20 at 15:59
  • there is no such switch; please see the screenshot at https://www.dropbox.com/s/hzlge170m0ws2u1/screenshot-from-2020-10-05-11-58-36.png?dl=0 – grobber Oct 05 '20 at 16:01
  • You're looking at the wrong tab. Show me the ipv4 tab. – heynnema Oct 05 '20 at 16:02
  • Ah, I see! Yes, it's set to `Automatic`. – grobber Oct 05 '20 at 16:03
  • Turn that to DISABLED, undo your dhcpcd edits, reboot, and see what happens. Are the DNS servers listed there also? – heynnema Oct 05 '20 at 16:04
  • I will, but as noted, I already have a working solution (which should be better documented anyway; these forceful `DHCP` `resolv.conf` rewrites come up much too often on these forums). Thanks for everything though! – grobber Oct 05 '20 at 16:06
  • Yes, but your working solution may not be the most correct solution, if my way also works for you. – heynnema Oct 05 '20 at 16:07
  • 1
    I don't know what "most correct" means, and I *certainly* prefer to know how to do this in a terminal; that's the more portable solution. So I prefer it to yours, I'm afraid. Again, thank you though. – grobber Oct 05 '20 at 16:10
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/113755/discussion-between-grobber-and-heynnema). – grobber Oct 05 '20 at 16:10
  • Rather than changing a file in `/lib`, a systemd [drop-in file](https://wiki.archlinux.org/title/Systemd#Drop-in_files) should be used to override the `ExecStart` line. Otherwise your changes might get overwritten by package upgrades. – Thomas Jun 30 '21 at 07:44