Alpine Linux sometimes DNS is not resolved

tl;dr

  1. Open file /etc/udhcpc/udhcpc.conf with a text editor.
    If the file is missing you just have to create it (and probably its containing folder).

  2. Append line

    RESOLV_CONF=no
    

Done.

Found here: https://wiki.alpinelinux.org/wiki/Udhcpc


The accepted answer wasn't satisfying in my case for

  • it's causing lots of stuff to be pasted without knowing what it's doing,
  • it's requiring installation of additional software and
  • it's just prepending given DNS server(s) to whatever it is writing into /etc/resolv.conf nonetheless instead of replacing it.

I'm sure there are more instructions on how to make dhclient replace stuff instead of prepending things, but that's too much research and headache for something as simple as preventing DHCP from replacing /etc/resolv.conf at all.


You can solve the problem by installing the dhclient package. For the last time enable Google's DNS servers by runing for the last time:

sudo su "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"

Then run this cocktail of commands:

sudo apk update && sudo apk upgrade && sudo apk add dhclient

In order to get the fresh packages and install the dhclient. Then configure the /etc/dhcp/dhclient.conf and put the following:

option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;

send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, domain-search, host-name,
        dhcp6.name-servers, dhcp6.domain-search, dhcp6.fqdn, dhcp6.sntp-servers,
        netbios-name-servers, netbios-scope, interface-mtu,
        rfc3442-classless-static-routes, ntp-servers;

prepend domain-name-servers 8.8.8.8, 8.8.4.4;

And restart the networking:

sudo rc-service networking restart

Optionally you can confirm that works if you run:

sudo reboot

In either case you can confirm that dns is resolved by pinging the google.

ping google.com