How to Change DNS Server on Linux
Table of Contents
Changing the DNS (Domain Name System) server on Linux is a simple process that can be done using the command line interface. This can be useful if you want to use a specific DNS server to improve your internet speed or security. In this article, we will discuss how to change the DNS server on Linux.
There are different ways to change the DNS server on Linux, but the most common method is to modify the configuration file of the network manager.
Debian/Ubuntu-based distros
Step 1: Open Terminal
Open the terminal by pressing Ctrl + Alt + T on your keyboard or by searching for it in the applications menu.
Step 2: Edit resolv.conf
Edit the /etc/resolv.conf file using a text editor such as nano or vim. This file contains the current DNS configuration of your system. To edit the file, run:
sudo nano /etc/resolv.conf
Find the line that starts with “nameserver” and replace the IP address with the IP address of the DNS server you want to use.
You can use multiple DNS servers by adding additional “nameserver” lines. For example, if you want to use Google’s DNS server (8.8.8.8), you can replace the line with:
nameserver 8.8.8.8
Step 3: Save Changes
Press Ctrl + X to exit nano and then press “Y” to save the changes. If you used a different text editor, use its save and exit functions.
Step 4: Restart Network Manager
Restart the network manager by running:
sudo systemctl restart network-manager.service
This will apply the changes you made to the DNS configuration.
Fedora/RPM-based distros
Step 1: Open Terminal
Open the terminal by pressing Ctrl + Alt + T on your keyboard or by searching for it in the applications menu.
Step 2: Edit resolv.conf
Edit the /etc/resolv.conf file using a text editor such as nano or vim. This file contains the current DNS configuration of your system. To edit the file, run:
sudo nano /etc/resolv.conf
Find the line that starts with “nameserver” and replace the IP address with the IP address of the DNS server you want to use.
You can use multiple DNS servers by adding additional “nameserver” lines. For example, if you want to use Google’s DNS server (8.8.8.8), you can replace the line with:
nameserver 8.8.8.8
Step 3: Save Changes
Press Ctrl + X to exit nano and then press “Y” to save the changes. If you used a different text editor, use its save and exit functions.
Step 4: Restart Network Manager
Restart the network manager by running:
sudo systemctl restart network.service
This will apply the changes you made to the DNS configuration.
Arch-based distros
Step 1: Open Terminal
Open the terminal by pressing Ctrl + Alt + T on your keyboard or by searching for it in the applications menu.
Step 2: Edit resolv.conf
Edit the /etc/systemd/resolved.conf file using a text editor. This file contains the current DNS configuration of your system. To edit the file, run:
sudo nano /etc/systemd/resolved.conf
Uncomment the line that starts with “DNS=” and replace the IP address with the IP address of the DNS server you want to use. You can use multiple DNS servers by separating them with a space. For example, if you want to use Google’s DNS server (8.8.8.8), you can replace the line with:
DNS=8.8.8.8
Step 3: Save Changes
Press Ctrl + X to exit nano and then press “Y” to save the changes. If you used a different text editor, use its save and exit functions.
Step 4: Restart systemd Resolved Service
Restart the systemd-resolved service by running:
sudo systemctl restart systemd-resolved.service
This will apply the changes you made to the DNS configuration.
Conclusion
In conclusion, changing the DNS server on Linux is a simple process that can be done using the command line interface. It is important to note that the changes you make to the DNS configuration will only affect the computer you are working on. If you want to change the DNS settings for your entire network, you will need to make changes to your router or DNS server.
Overall, changing the DNS server on Linux can improve your internet speed and browsing experience. By using a reliable and fast DNS server, you can avoid delays caused by slow DNS resolution times and ensure that your web requests are handled efficiently. Whether you are a network administrator or a home user, learning how to change the DNS server on Linux is a valuable skill that can benefit you in many ways.