Linux – Alpine Linux sometimes DNS is not resolved

alpine-linuxresolv.conf

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 8.8.8.8' > /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?

Best Answer

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.

Related Question