DropVPS Team
Writer: Cooper Reagan
How to change dns in linux command line

Table of Contents
What you will read?
Changing the DNS settings on your Linux system can be a straightforward process, especially when you do it through the command line. Whether you want to use a public DNS server like Google DNS or Cloudflare DNS, this guide will walk you through the steps required to modify your DNS settings effectively.
Open the Terminal
You can access the terminal on most Linux distributions by searching for “Terminal” in your applications menu or by pressing Ctrl + Alt + T.
Check Current DNS Settings
Before making any changes, it’s a good idea to check your current DNS settings. You can do this by using the following command:
cat /etc/resolv.conf
This file typically contains the nameservers currently in use.
Backup the Current Configuration
It’s always a good practice to back up your configuration before making changes. You can create a backup of the resolv.conf file with this command:
sudo cp /etc/resolv.conf /etc/resolv.conf.backup
Edit the resolv.conf File
To change your DNS settings, you’ll need to edit the resolv.conf file. Use your favorite text editor; here, we’ll use nano:
sudo nano /etc/resolv.conf
Once you have the file open, you can add or modify the nameserver entries. For example, to use Google DNS, you would add:
nameserver 8.8.8.8
nameserver 8.8.4.4
If you prefer Cloudflare, replace those lines with:
nameserver 1.1.1.1
nameserver 1.0.0.1
After making your changes, save the file and exit the editor (in nano, you can do this by pressing CTRL + X, then Y, and ENTER).
Restart Network Services
To ensure the changes take effect, restart your networking service. Depending on your Linux distribution, the command may vary. For most systems using systemd, you can run:
sudo systemctl restart NetworkManager
Alternatively, you can use the following command for older systems:
sudo service networking restart
Verify the Changes
To confirm that your DNS settings have been updated, you can run:
cat /etc/resolv.conf
You should see your new DNS servers listed.
Testing Your DNS Configuration
To test if the new DNS servers are working, you can use the dig command (you may need to install it first with sudo apt install dnsutils):
dig google.com
Look for the SERVER line in the output to see if it matches your new DNS server. Changing DNS settings in Linux through the command line is a simple process that can provide numerous benefits. By following the steps outlined above, you can easily switch to a DNS provider that meets your needs, enhancing your online experience. For more tips on Linux and server management, stay tuned to DropVPS.com!