Software & AppsOperating SystemLinux

How To Set a Static DNS Nameserver Address on Ubuntu Server

Ubuntu 19

In this tutorial, we will walk you through the process of setting a static DNS nameserver address on an Ubuntu Server. This can be particularly useful if you want to ensure that your server always uses a specific DNS server for its name resolution.

Quick Answer

To set a static DNS nameserver address on Ubuntu Server, you need to modify the network interfaces file and specify the desired DNS server address. After making the changes, restart the networking service for the changes to take effect. Additionally, if your DNS server addresses are being overwritten by your ISP’s DNS servers, you can disable the resolvconf service and manually create the /etc/resolv.conf file with your desired DNS server addresses.

What is a DNS Nameserver?

The Domain Name System (DNS) is a hierarchical and decentralized naming system for computers, services, or other resources connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities. A DNS nameserver, in simple terms, is a server that contains a database of public IP addresses and their associated hostnames. It is responsible for providing responses to queries against its database.

Prerequisites

Before we begin, you should have:

  • A running Ubuntu Server
  • Root or sudo access to the server

Setting a Static DNS Nameserver Address

Step 1: Accessing the Network Interfaces File

First, we need to access the network interfaces file. This file contains all the necessary configurations for your network interfaces. You can access it by using the following command:

sudo nano /etc/network/interfaces

Here, nano is a command-line text editor, and /etc/network/interfaces is the path to the network interfaces file. sudo is used to run the command with root privileges.

Step 2: Modifying the Network Interface Configuration

In the network interfaces file, locate the line that starts with iface eth0 inet dhcp or similar. This line is for the network interface that you want to configure. Change dhcp to static:

iface eth0 inet static

The iface keyword is used to define the configuration for a network interface. eth0 is the name of the network interface, inet specifies that the configuration is for IPv4, and static means that the interface will use a static IP address.

Step 3: Setting the DNS Nameserver Address

Below the line you just modified, add the following line, replacing x.x.x.x with the DNS server address you want to use:

dns-nameservers x.x.x.x

The dns-nameservers option is used to specify the DNS nameservers that the network interface should use.

Step 4: Applying the Changes

After saving and exiting the text editor, you need to restart the networking service for the changes to take effect:

sudo systemctl restart networking

Here, systemctl is a command used to control the systemd system and service manager, restart is an option that restarts a service, and networking is the name of the service to restart.

Troubleshooting

If you find that your DNS server addresses are being overwritten by your ISP’s DNS servers, you can disable the resolvconf service and manually create the /etc/resolv.conf file.

Step 1: Disabling the resolvconf Service

To disable the resolvconf service, use the following command:

sudo systemctl disable resolvconf

Step 2: Removing the Symbolic Link to resolv.conf

Next, remove the symbolic link to /etc/resolv.conf:

sudo rm /etc/resolv.conf

Step 3: Creating a New resolv.conf File

Now, create a new /etc/resolv.conf file and add your desired DNS server addresses:

sudo nano /etc/resolv.conf

In the file, add the following lines, replacing x.x.x.x with your desired DNS server address:

nameserver x.x.x.x

The nameserver keyword is used to specify a DNS nameserver.

Step 4: Applying the Changes

After saving and exiting the text editor, the changes should take effect immediately.

Conclusion

Setting a static DNS nameserver address on Ubuntu Server can seem complex due to factors such as mobility and autoconfiguration. However, with this guide, you should be able to confidently set a static DNS nameserver address on your Ubuntu Server. Remember to replace x.x.x.x with the actual DNS server address that you want to use.

What is the purpose of setting a static DNS nameserver address on Ubuntu Server?

Setting a static DNS nameserver address allows you to ensure that your server always uses a specific DNS server for its name resolution. This can be useful for maintaining consistency and reliability in your network.

How do I access the network interfaces file on Ubuntu Server?

You can access the network interfaces file by using the command sudo nano /etc/network/interfaces. This will open the file in the nano text editor with root privileges.

How do I modify the network interface configuration in the network interfaces file?

In the network interfaces file, locate the line that starts with iface eth0 inet dhcp or similar. Change dhcp to static to set the interface to use a static IP address.

How do I set the DNS nameserver address?

Below the line you modified in the network interfaces file, add the line dns-nameservers x.x.x.x, replacing x.x.x.x with the DNS server address you want to use.

How do I apply the changes after modifying the network interfaces file?

After saving and exiting the text editor, you need to restart the networking service using the command sudo systemctl restart networking for the changes to take effect.

What should I do if my DNS server addresses are being overwritten by my ISP’s DNS servers?

If your DNS server addresses are being overwritten, you can disable the resolvconf service and manually create the /etc/resolv.conf file with your desired DNS server addresses.

How do I disable the resolvconf service?

To disable the resolvconf service, use the command sudo systemctl disable resolvconf.

How do I create a new resolv.conf file?

To create a new /etc/resolv.conf file, use the command sudo nano /etc/resolv.conf. In the file, add the line nameserver x.x.x.x, replacing x.x.x.x with your desired DNS server address.

How do I apply the changes after creating the new resolv.conf file?

After saving and exiting the text editor, the changes should take effect immediately.

Leave a Comment

Your email address will not be published. Required fields are marked *