How to deal with Alpine DNS issues

How to deal with Alpine DNS issues

Apr 7, 2023
Dmitry Chuyko

Alpine Linux is a go-to OS for those striving to reduce the size of their containers. It is secure, minimalistic, performant, and free-to-use. What’s there not to like? All is well until one day your Kubernetes clusters start behaving strangely. A closer look at the logs will tell you that the devil is in the DNS, namely in the way your Alpine-based application deals with it. And this devil is hard to chase away.

Read on to know how the DNS problems may arise and what you could do to solve or prevent them.

The root cause of Alpine DNS issues

How the problem manifests

The issues with DNS resolution exist in musl-based distributions, one of which is Alpine. In a nutshell, an application running in a Docker container on Kubernetes resolves most DNS queries normally, but in case of larger DNS entries, it throws the UnknownHostException or a similar exception such as

/ # ping
ping: bad address ''

and the host resolution fails.

This DNS issue is reproducible in specific cases only. For instance, large DNS requests can be encountered in environments like K8s with many nodes running Ingress. But in the majority of cases, the DNS resolution works fine.

The downside is that this issue is unpredictable. Even if your containerized application runs fine on Kubernetes now, one day a large DNS entry comes your way and causes havoc in your clusters.

musl specifics

musl is a lightweight alternative to the glibc libc. It provides smaller overhead, but unfortunately, comes hand in hand with the above DNS problem. Note that this is not a musl bug, but intended behavior stemming from the functional difference between musl and glibc resolvers. musl supports DNS over UDP (user datagram protocol) only, and doesn’t support DNS over TCP, which is used for packets larger than 512 bytes. It also doesn’t support the feature specified by the RFC standard, which allows to increase the size of the UDP packet above 512 bytes (limit for DNS over UDP) via the Extension Mechanism for DNS (EDNS). This leads to limited support for big DNS packets in musl, so in case of large DNS responses, musl resolver exits.

The musl author explains that he didn’t add TCP support for the sake of improved performance. Indeed, UPD enables data transmission without establishing or verifying connection, which results in faster data transfer. TCP, in turn, uses a handshake between client and server leading to higher latency and overhead.

There are other peculiarities concerning DNS resolution in musl which may cause additional problems. For instance, musl performs parallel querying of name servers and can’t switch to sequential one like glibc. So if you start the Docker daemon with --dns= --dns=, where the former is the local DNS server and the latter is used for external DNS resolving, there is no guarantee that will be tried first, which will lead to unforeseen failures.

To find out more about differences between musl and glibc, refer to a dedicated guide.

Possible solutions

There are feasible workarounds for the issues mentioned above. Firstly, use fully qualified domain names (FQDN) to avoid resolution failures. An FQDN in DNS records ends with a dot (for instance, “” is a FQDN, whereas “” is not). Secondly, you can use a local caching DNS server for caching and search path routing. It will reduce the load on the CPU and network and can even speed up name resolution in glibc to overcome a sequential nature of the requests there.

Below is the example of setting up a caching server with a flexible tool dnsmasq:

apk add dnsmasq

cat > /etc/resolv.conf << EOF

cat >> /etc/dnsmasq.conf << EOF

rc-update add dnsmasq default
rc-service dnsmasq start

Finally, you can use a specialized DNS library to resolve queries longer than 512 bytes.

As far as the problem with large DNS queries is concerned, the Alpine community is aware of it and has been working on fixes for quite a while now. The exciting news is that the fixes are ready! The following set of patches applied from the musl upstream repository adds DNS TCP fallback support and additional network fixes.


These patches allow the developers to use TCP for DNS-related data exchange. For instance, you can check a large DNS reply by calling getaddrinfo() (54 A records Before the patches, we could see the following output:

IP > 7847+ A? (34)

IP > 7847*-| 29/0/0 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A (498)

IP > 8614+ AAAA? (34)

IP > 8614*- 0/1/0 (79)

However, with the patches, the result is:

IP > 2485+ A? (34)

IP > 3608+ AAAA? (34)

IP > 2485*-| 29/0/0 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A (498)

IP > 3608*- 0/1/0 (79)

IP > Flags [S], seq 562297716, win 64240, options [mss 1460,sackOK,TS val 2626445450 ecr 0,nop,wscale 9,exp-tfo cookiereq], length 0

IP > Flags [S.], seq 877696001, ack 562297717, win 65535, options [mss 1460], length 0

IP > Flags [.], ack 1, win 64240, length 0

IP > Flags [P.], seq 1:37, ack 1, win 64240, length 36 2485+ A? (34)

IP > Flags [.], ack 37, win 65535, length 0

IP > Flags [P.], seq 1:901, ack 37, win 65535, length 900 2485*- 54/0/0 A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A, A (898)

IP > Flags [.], ack 901, win 63900, length 0

IP > Flags [R.], seq 37, ack 901, win 63900, length 0

These patches are already integrated into Alpine 3.18, so upgrading will eliminate the above issues.

However, if you are not planning to upgrade Alpine version soon, or don't want to wait for another long-lasting problem to emerge, consider migration to Alpaquita Linux, a 100 % Alpine-compatible distribution backed by vendor support.

Lightweight Alpaquita Linux with musl and glibc

The motivation behind Alpaquita was to provide companies with a small Linux distribution that overcomes known Alpine issues, including the ones described above. Therefore, we provide two Alpaquita options: with optimized musl and glibc.

The BellSoft engineers took the above patches from the musl upstream repository and integrated them into our musl builds for Alpaquita. Therefore, you can use Alpaquita Linux with optimized musl without the risk of encountering DNS issues.

However, if you have been using glibc-based Linux or are still cautious about musl, take a look at our glibc-based Alpaquita variant. It is almost as small as Alpine (8.32 MB), and we also tuned the libc implementation so that it shows even better performance than the default glibc in some cases.

Comparison of container images based on various Linux distribution

Alpaquita comes with other enhancements as well:

  • Increased kernel performance;
  • Additional security features;
  • Four malloc implementations for various workloads;
  • LTS releases as part of commercial support.

Coupled with Liberica Lite, Alpaquita enables you to create microcontainers without sacrificing performance and usability.

Have we piqued your interest? Download the white paper on Alpaquita to learn more about our Linux distro: technical characteristics, support options, and comparative performance studies. Or head over to Docker Hub and try free Alpaquita Stream with your application right now!

Get Alpaquita Linux White Paper

Subcribe to our newsletter


Read the industry news, receive solutions to your problems, and find the ways to save money.

Further reading