Ludovic Frank - Freelance developer

Ubuntu server, quickly change DNS servers

ionicons-v5-k Ludovic Frank May 8, 2023
71 reads Level:

Hello ?,
This week's article is based on something that happened to me recently. During an Ubuntu server update, it seems that the bind9 package, after the update, started to crash after a while.

The problem is that on this machine, I need DNS resolution, as it hosts services that need to complicate with other online services like Stripe.

So I end up with a call informing me that when it comes to entering the bank card on this Symfony application, well, it doesn't display the form requesting the card... weird?
Actually, it's not as weird as all that. I'd already noticed that after that night's update, the bind9 service was becoming unstable, which is a shame, since it's the service that creates a DNS cache for the machine.

As you can imagine, that's what we'll be talking about in this article...

Bind9, also used as a local DNS cache.

Bind9, an Open Source DNS server, is sometimes used as a DNS cache, as is the case at Scaleway. By default, when you receive a server running Ubuntu, it will use a local cache, and this local cache will be provided by Bind9.
This avoids "spamming" DNS servers for recurring DNS requests.

How do I know my DNS servers?

To find out which DNS servers are running on your server, it's pretty straightforward (although?), just look at the contents of the "/etc/resolv.conf" file, which you can do with the command "cat /etc/resolv.conf".

An example of a "/etc/resolv.conf" file

Why "Whatever?"
As I said above, sometimes bind9 is used as a DNS server, so in the list of DNS servers you'll see "127.0.0.1", i.e. your local IP address. This is simply the bind9 server listening for DNS requests locally.

Finally, you can use the dig command to check that DNS resolution is correct, for example: "dig developpeur-freelance.io".

An example of the "dig" command response

In this example, you can see that server "62.210.16." has been used.

The resolvconf facility

Installation

The idea here is not to worry too much about it, there's another method, but we'll stick with the easy way, first, install "resolvconf" with the command: "sudo apt-get install resolvconf"

Configuration

Once the package has been installed, you'll need to move on to its configuration, which is relatively straightforward: edit the "/etc/resolvconf/resolv.conf.d/head" file and set the DNS you want, in this example, Google's (yes, I know ... ?):

An example of a "/etc/resolvconf/resolv.conf.d/head" file

The syntax is the same as in "/etc/resolv.conf", but this one, unlike the other, you have the right to modify?

Applying the configuration

To activate everything, simply enter the command "sudo systemctl enable --now resolvconf.service".
Then you can do a "dig" to test if everything's OK, e.g. "dig developpeur-freelance.io".

Conclusion

For those who want to go further, when I had my DNS problem, the basis was this article.

Now you know how to change your DNS simply on Ubuntu server?
Until next time.