Edited 3 weeks ago by ExtremeHow Editorial Team
DNSNetworkingUbuntuLinuxConfigurationOperating SystemsInternetSystemDesktopAdministration
This content is available in 7 different language
Changing DNS settings on Ubuntu is an essential skill for those who want to manage their own network settings. DNS stands for Domain Name System, and it's like the phone book of the Internet. It translates human-friendly domain names into machine-readable IP addresses.
By changing DNS settings, you gain more control over how your system interacts with hosts on the Internet. This can improve your browsing speed, security, and reliability because it allows your machine to ask different DNS servers for information instead of the default DNS servers provided by your Internet service provider (ISP).
DNS plays a vital role by converting domain names like www.example.com
into IP addresses like 192.168.1.1
. This process, known as DNS resolution, is crucial for accessing websites, sending emails, and more.
Imagine if every website was accessed via IP addresses instead of names; this would be cumbersome and impractical for users. DNS simplifies this process by maintaining a distributed database and providing resolving services.
Why would you need to change DNS settings, you might ask? There are several reasons for this:
Let’s explore the methods available to change DNS settings on Ubuntu in simple and understandable terms. We will learn about the various configurations possible in Ubuntu.
This method is straightforward and doesn't require much technical knowledge. Ubuntu's Network Manager provides a graphical user interface to easily change network connection settings.
8.8.8.8
and 8.8.4.4
.With these steps, you have updated your DNS settings using the graphical interface. If you have more than one network, each network connection may require different configuration.
If you’re comfortable using the terminal, you can change DNS settings through the command line, which is sometimes quicker and offers more control.
/etc/resolv.conf
The file /etc/resolv.conf
usually contains DNS configurations. However, in many modern systems, it is managed by a system service and may come back after a reboot. To edit it temporarily, you can use:
$ sudo nano /etc/resolv.conf
$ sudo nano /etc/resolv.conf
Once the file is open, add or modify the lines to change the DNS entries:
nameserver 8.8.8.8 nameserver 8.8.4.4
nameserver 8.8.8.8 nameserver 8.8.4.4
Save the file and exit the editor. Remember, changes made directly to /etc/resolv.conf
are often temporary.
resolvectl
(for systems with systemd-resolv)Many Ubuntu systems use systemd-resolved; therefore, the command to manage DNS settings is resolvectl
.
$ sudo resolvectl dns <YOUR_INTERFACE_NAME> 8.8.8.8 8.8.4.4 $ sudo resolvectl domain <YOUR_INTERFACE_NAME> example.com
$ sudo resolvectl dns <YOUR_INTERFACE_NAME> 8.8.8.8 8.8.4.4 $ sudo resolvectl domain <YOUR_INTERFACE_NAME> example.com
Replace <YOUR_INTERFACE_NAME>
with your network interface, such as wlan0
for wireless or eth0
for a wired connection.
For permanent DNS settings, you should configure your network manager or netplan
(for systems using it) configuration.
On Ubuntu with Netplan, you can define permanent DNS settings by editing YAML configuration files located in /etc/netplan/
.
Edit the appropriate YAML file:
$ sudo nano /etc/netplan/01-netcfg.yaml
$ sudo nano /etc/netplan/01-netcfg.yaml
Within the file, add or modify the following structure:
network: version: 2 ethernets: eth0: dhcp4: yes nameservers: addresses: [8.8.8.8, 8.8.4.4]
network: version: 2 ethernets: eth0: dhcp4: yes nameservers: addresses: [8.8.8.8, 8.8.4.4]
Save and exit. Apply the changes with the following:
$ sudo netplan apply
$ sudo netplan apply
Sometimes, despite changing the DNS settings, you may face issues like DNS cache not getting cleared or settings not getting applied. Here are some general tips you can try for troubleshooting:
systemd-resolved
service often helps:
$ sudo systemctl restart systemd-resolved.service
$ sudo systemctl restart systemd-resolved.service
$ resolvectl status
$ resolvectl status
/etc/netplan/01-netcfg.yaml
are formatted correctly, as YAML is sensitive to file structure.By following these methods, you can effectively manage DNS settings on Ubuntu, either through the graphical interface or direct command-line methods. Knowing this not only gives you better control over your networking setup but also provides a better browsing experience by having reliable, fast, and secure DNS servers.
Always remember to properly test DNS changes by accessing a website or running various network checks. This ensures that your DNS configurations are applied correctly and are improving your system's networking capabilities as expected.
If you find anything wrong with the article content, you can