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:
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:
For example, to add Google's DNS servers, add the following lines:
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.
- To use OpenDNS servers, add the following lines:
- To use Cloudflare DNS servers, add the following lines:
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:
That's it for this post. Keep practicing and have fun. Leave your comments if any.