18

Every 6 months or so I cannot access the DNS on whatever router I'm using. usually have to add the nameserver by hand to the /etc/resolv.conf file. I've tried adding Google free DNS to the file and it changes nothing. What can I do to not have to manually change the file each time I go to different coffee shop?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
John Coder
  • 181
  • 1
  • 1
  • 3

2 Answers2

25

You can add the following line to /etc/dhcp/dhclient.conf:

prepend domain-name-servers <working DNS IP(s) here>;

This adds the DNS IP address(es) you specify before that/those provided by the DHCP. If you would like to add it/them after the address(es) provided by the DHCP, just use

append domain-name-servers <working DNS IP(s) here>;

If, instead you would like to ignore the DNS address(es) provided by the DHCP altogether, use

supersede domain-name-servers <working DNS IP(s) here>;
Joseph R.
  • 38,849
  • 7
  • 107
  • 143
  • not sure I had to do this from my windoze box since I don't have DNS capabilities at all. I can ping the quad-notation just no nameserver recognition – John Coder Jul 25 '14 at 01:28
  • @JohnCoder I'm not sure I understand what you're saying. Please clarify... – Joseph R. Jul 25 '14 at 01:29
  • 1
    I can ping for instance the google dns 8.8.8.8 but I cannot ping goggle.com on the Linux box but I'm posting this from my windows box since I cannot access the nameserver from my Linux box. I'll reboot and see. – John Coder Jul 25 '14 at 01:33
  • @JohnCoder What do you get with `host google.com 8.8.8.8`? – Joseph R. Jul 25 '14 at 01:39
  • Haven't tried that yet I'm networking now through the Linux box so the nameserver issue is taken care of now. But as I've said I go through this every 6 months or so. everything will be peachy for 6 months, then all of a sudden it doesn't resolve the domain name.And I go through this again. – John Coder Jul 25 '14 at 03:46
  • host google.com 8.8.8.8 Using domain server: Name: 8.8.8.8 Address: 8.8.8.8#53 Aliases: google.com has address 173.194.33.40 google.com has address 173.194.33.37 google.com has address 173.194.33.39 google.com has address 173.194.33.36 google.com has address 173.194.33.41 google.com has address 173.194.33.32 google.com has address 173.194.33.46 google.com has address 173.194.33.35 google.com has address 173.194.33.33 google.com has address 173.194.33.34 google.com has address 173.194.33.38 – John Coder Jul 25 '14 at 04:02
  • @JosephR. Should I see prepended address in /etc/resolv.conf after reboot? – Al Bundy Dec 19 '18 at 12:12
  • 1
    Probably worth noting that this only works if the user is using ISC dhcp client. – Sam Morris Jan 06 '22 at 14:55
6

You can tell NetworkManager to ignore the DHCP provided DNS servers, by putting this in the network's config file (/etc/NetworkManager/system-connections/my-essid if saved to the system).

The important bit is ignore-auto-dns=true

[ipv4]
ignore-auto-dns=true
dns=8.8.8.8;
method=auto
tumbleweed
  • 530
  • 4
  • 5
  • 3
    Is there any way to enforce this setting on all connections? I mean, can I set this as a default, so when I connect to another wifi, it will automatically ignore its DHCP's DNS? – Vojtech Kane Apr 29 '20 at 08:54
  • `nmcli dev show` still shows my router's address as DNS server after doing this change and disconnect/reconnect. This doesn't work. – Calmarius Apr 11 '23 at 20:40