k3s ·

Configuring DNS Servers in UMH Instances

Learn how to configure custom DNS servers on your UMH instance to resolve external domain names and prevent connectivity issues. This step-by-step guide covers editing `/etc/resolv.conf`, restarting CoreDNS pods, and customizing the CoreDNS ConfigMap for advanced DNS configurations.

Configuring DNS Servers in UMH Instances
💡
This question was originally asked by R2rho on our Discord channel. Here is the original thread.

When connecting to external devices via their DNS addresses in the UMH, you might encounter errors like:

level=error msg="Failed to connect to sql_raw: lookup myserverlocation.com on 10.43.0.10:53: no such host" @service=benthos label=sql_input path=root.input

This error indicates that your custom DNS server was not properly detected by the UMH instance. This can happen if the DNS settings were not propagated via DHCP when setting up the operating system behind the UMH instance.

To resolve this issue, follow these steps to configure your DNS servers:

Steps to Configure DNS Servers

1. Update /etc/resolv.conf

SSH into your UMH instance and edit the /etc/resolv.conf file:

sudo nano /etc/resolv.conf

Add or modify the nameserver entries to include your preferred DNS servers:

nameserver 100.64.0.2
nameserver 1.1.1.1
nameserver 8.8.8.8
Note: Replace 100.64.0.2, 1.1.1.1, and 8.8.8.8 with the IP addresses of your custom DNS servers.

Save and close the file.

2. Restart CoreDNS Pods

CoreDNS, the DNS server running within your Kubernetes cluster, should automatically load the updated /etc/resolv.conf. However, to ensure it picks up the changes, restart the CoreDNS pods:

sudo $(which kubectl) --kubeconfig /etc/rancher/k3s/k3s.yaml
-n kube-system delete pods -l k8s-app=kube-dns

This command deletes the existing CoreDNS pods, and Kubernetes will automatically recreate them with the updated configuration.

Edit CoreDNS ConfigMap (Optional)

If restarting CoreDNS doesn't resolve your DNS issues, you can manually edit the CoreDNS ConfigMap to specify your custom DNS servers directly.

Step 1: Edit the ConfigMap

sudo $(which kubectl) --kubeconfig /etc/rancher/k3s/k3s.yaml
-n kube-system edit configmap coredns

Step 2: Modify the forward Section

In the ConfigMap editor, locate the forward plugin section and modify it to include your DNS servers. Here are some examples:

Use a Single External DNS Server:

forward . 1.1.1.1

Use External DNS and /etc/resolv.conf:

forward . 1.1.1.1 /etc/resolv.conf

Use Multiple DNS Servers with Round-Robin and Failover:

forward . 1.1.1.1 8.8.8.8

Enable Detailed Logging (Optional): Add the log directive to enable verbose logging:

log

Step 3: Save and Exit

After making the necessary changes, save and exit the editor.

Step 4: Restart CoreDNS Pods

sudo $(which kubectl) --kubeconfig /etc/rancher/k3s/k3s.yaml
-n kube-system delete pods -l k8s-app=kube-dns

Conclusion

By following these steps, you should be able to configure your UMH instance to use your custom DNS servers, ensuring proper domain resolution for your applications both within the cluster and in your external network environment.

Read next

Share, Engage, and Contribute!

Discover how you can share your ideas, contribute to our blog, and connect with us on other platforms.