How to Set DNS Server in Ubuntu Command Line?
Setting up DNS servers in Ubuntu via the command line can be a straightforward and efficient process. Whether you're configuring DNS for network optimization, privacy, or troubleshooting connectivity issues, this guide will walk you through the steps to set DNS servers using the command line interface.
Checking Current DNS Configuration:
Before making any changes, it's essential to verify your current DNS configuration. Open a terminal and use the following command:
This will display the current DNS settings, including the nameservers and search domains.
Determining the Network Interface:
Identify the network interface you want to configure. Use the following command to list all network interfaces:
ip link show
Typically, you'll see interfaces like "eth0" or "wlan0". Choose the interface you're connected to.
Changing DNS Servers:
Now, let's change the DNS servers for your chosen network interface. Replace "interface_name" with your actual interface name and "DNS_server_IP" with the desired DNS server address.
sudo nano /etc/network/interfaces
Add the following lines at the end of the file:
Save and exit the editor.
To apply the changes without restarting the network service, use the following command:
sudo systemctl restart networking
Confirm that the changes were successful by checking the updated configuration:
You should now see the new DNS server listed.
Alternative Method - Using Netplan:
If you're using Ubuntu 18.04 or later, Netplan might be the preferred method. Open the Netplan configuration file for editing:
sudo nano /etc/netplan/01-netcfg.yaml
Add the DNS servers under the appropriate network interface:
Apply the changes:
sudo netplan apply
Testing DNS Resolution:
Verify that DNS resolution is working as expected by using the following command:
Replace "example.com" with the domain you want to test.
Backup: Before making changes, consider creating a backup of configuration files to avoid potential issues.
Multiple DNS Servers: You can specify multiple DNS servers by separating their IP addresses with commas.
Related Searches and Questions asked:
That's it for this topic, Hope this article is useful. Thanks for Visiting us.