How do I set DNS servers in Linux?

To set DNS servers in Linux, you can edit the /etc/resolv.conf file directly by adding lines like:

nameserver <DNS_server_IP>

However, if you’re using NetworkManager, it’s better to configure DNS servers using nmcli:

nmcli con mod <connection_name> ipv4.dns "<DNS_server_IP>"
nmcli con up <connection_name>

Alternatively, if you’re using systemd-resolved, you can edit /etc/systemd/resolved.conf to specify DNS servers and then restart the service.

About The Author
Agneta Venckute is the Marketing Manager at Hostline with over 6 years of experience in technology marketing. Her love for creative problem-solving and exploring new technological advancements drives her to design engaging marketing campaigns that captivate and educate consumers.
Subscribe to our newsletter