DEV Community

David Ngugi
David Ngugi

Posted on

1

Change default nameserver in Linux

My internet provider provides a wifi router that is pre-configured with DHCP that also provides the nameserver as their internal DNS server. There is a ton of info about why you wouldn't want this and they revolve about 2 main issues; security and performance.

Fedora 40

On Fedora, the wifi is managed by Network manager. I chose to use cloud-dns with encryption so that no-one in the middle can see what I am looking up on the internet. I chose cloud-dns because they tend to be more performant than Google nameservers.

Additionally, I also want to persistent these changes to all wifi connections regardless of which wifi network I use which is handy for laptops on the move.

Create a global NetworkManager configuration file

sudo nano /etc/NetworkManager/conf.d/dns-override.conf
Enter fullscreen mode Exit fullscreen mode

Add the following content

[main]
dns=none
Enter fullscreen mode Exit fullscreen mode

This tells NetworkManager not to use DHCP-assigned DNS.

Override DNS for all Wi-Fi connections

sudo nano /etc/NetworkManager/conf.d/dns-servers.conf
Enter fullscreen mode Exit fullscreen mode

Add:

[global-dns]
servers=1.1.1.2,1.0.0.2
Enter fullscreen mode Exit fullscreen mode

Enable DNS Over TLS
Open sudo nano /etc/systemd/resolved.conf and copy the following in

[Resolve]
DNS=1.1.1.2 1.0.0.2
DNSOverTLS=yes
Enter fullscreen mode Exit fullscreen mode

Restart systemd-resolved and NetworkManager

sudo systemctl restart systemd-resolved
sudo systemctl restart NetworkManager
Enter fullscreen mode Exit fullscreen mode

Debian based Linux

Disable DHCP-provided DNS from Wi-Fi Interface
Edit the sudo nano /etc/systemd/network/20-wireless.network
configuration for your interface (if applicable):

[Network]
DNS=1.1.1.2 1.0.0.2
DNSOverTLS=yes
Domains=~.
Enter fullscreen mode Exit fullscreen mode

Restart networking services

sudo systemctl restart systemd-networkd
Enter fullscreen mode Exit fullscreen mode

AWS Q Developer image

Your AI Code Assistant

Implement features, document your code, or refactor your projects.
Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more