Sometimes when I run the commands:

sudo apk update && sudo apk upgrade

Over Alpine linux fails to update the packages even if connected to internet. But if I do sudo su "echo 'nameserver' > /etc/resolv.conf" I manage to dowload them. But this solution:

  • Causes me frustration I need to set dns all over the time.
  • Sometimes /etc/resolv.conf gets overriden by itself.

How I can have a more permanent solution?

3 Answers 3



  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



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.

  • Seems it should be RESOLV_CONF="no". Did not work without "" in my case.
    – Mario Eis
    Nov 22, 2019 at 0:00
  • In my case omitting the quotation marks is working just fine. The file is included by /usr/share/udhcpc/default.script using /bin/sh so quotation marks should not make a difference unless the value contains whitespace or other functional characters of shell which doesn't apply to no. I assume there was a different issue in your case or maybe your version is different. In my case it's Alpine 3.10.3. Nov 22, 2019 at 8:58

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' > /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,;

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

Udhcpc need /etc/udhcpc/udhcpc.conf, accessible by all, with a single line dns="ns1 ns2"


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .