You can Watch all our Tutorials and Training Videos on our YouTube Channel for Free! Subscribe Now!

How to Set DNS Server in Ubuntu Command Line?

How to Set DNS Server in Ubuntu Command Line, ?, linux dns server, linux dns server configuration, simple dns server linux, configure dns, DevOps
Admin
How to Set DNS Server in Ubuntu Command Line

Domain Name System (DNS) servers play a crucial role in the internet's functionality. It translates domain names into IP addresses, enabling communication between computers. By default, Ubuntu retrieves DNS server addresses from the router or modem through DHCP. However, sometimes, you may need to configure DNS servers manually, like when your ISP's DNS servers are slow or unreliable.

This article will guide you through the steps to set DNS servers in Ubuntu command line.

Step 1: Check the Current DNS Settings

Before changing the DNS server, you need to check the current settings. You can use the "nmcli" command-line utility to display the current DNS settings. Open the terminal and enter the following command:

nmcli dev show | grep DNS

This command will display the current DNS servers.

Step 2: Backup the Current Configuration

It is always wise to backup the current DNS configuration before making any changes. In case something goes wrong, you can easily revert to the previous settings. Use the following command to backup the current DNS configuration:

sudo cp /etc/resolv.conf /etc/resolv.conf.backup

Step 3: Edit the DNS Configuration File

The DNS configuration file is located at "/etc/resolv.conf." Open the file with a text editor using the following command:

sudo nano /etc/resolv.conf

By default, Ubuntu uses the "systemd-resolved" DNS resolver. To add DNS servers manually, you need to disable it first. Add the following line at the top of the file to disable the resolver:

nameserver 127.0.0.53#53

Now, add the DNS server addresses you want to use. You can add multiple servers, but the order matters. Ubuntu will use the first DNS server in the list and only use the second one if the first one fails. To add DNS servers, use the following syntax:

nameserver [DNS-Server-IP-Address]

For example, to add Google's DNS servers, add the following lines:

nameserver 8.8.8.8
nameserver 8.8.4.4

Step 4: Save and Close the File

After adding the DNS servers, save and close the file by pressing "Ctrl+X," then "Y," and finally "Enter."

Step 5: Restart the Networking Service

To apply the changes, restart the networking service using the following command:

sudo systemctl restart networking.service

Alternatively, you can restart the network-manager service using the following command:

sudo systemctl restart NetworkManager.service

Step 6: Verify the DNS Configuration

After restarting the networking service, use the "nmcli" command again to verify that the DNS servers have been updated. Enter the following command:

nmcli dev show | grep DNS

You should see the new DNS servers listed.

More Examples

  • To use OpenDNS servers, add the following lines:
nameserver 208.67.222.222
nameserver 208.67.220.220
  • To use Cloudflare DNS servers, add the following lines:
nameserver 1.1.1.1
nameserver 1.0.0.1

Setting DNS servers manually in Ubuntu is a simple process that can help improve your internet experience. By following the steps outlined above, you can easily set the DNS servers in Ubuntu command line.

Related Searches and Questions asked:

  • Linux DNS Server List
  • Linux DNS Server Configuration
  • What is an example of DNS server software?
  • Setting Up a Linux DNS Server on Ubuntu
  • That's it for this post. Keep practicing and have fun. Leave your comments if any.

    Post a Comment

    Cookie Consent
    We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
    Oops!
    It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
    AdBlock Detected!
    We have detected that you are using adblocking plugin in your browser.
    The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
    Site is Blocked
    Sorry! This site is not available in your country.