Skip to content

Instantly share code, notes, and snippets.

@MM25Zamanian
Created June 30, 2025 11:23
Show Gist options
  • Save MM25Zamanian/d9ea23da0016e95a87dc0fa4b4fd1374 to your computer and use it in GitHub Desktop.
Save MM25Zamanian/d9ea23da0016e95a87dc0fa4b4fd1374 to your computer and use it in GitHub Desktop.

πŸ“˜ How to Change DNS on Debian 12

This guide explains how to change the DNS servers on a Debian 12 system. DNS (Domain Name System) is used to resolve domain names (like example.com) into IP addresses.


βœ… Method 1: Temporary Change (for testing)

You can temporarily change DNS by editing the /etc/resolv.conf file directly. This change will be lost after reboot or network restart.

πŸ”§ Steps:

  1. Open the file with a text editor:

    sudo nano /etc/resolv.conf
  2. Add or edit nameserver entries. For example:

    nameserver 1.1.1.1
    nameserver 8.8.8.8
    
  3. Save and exit (press CTRL+O, then Enter, then CTRL+X).

  4. Test DNS resolution:

    ping google.com

⚠️ Warning: On Debian 12, this file may be managed by systemd-resolved or the dhclient. So changes here might get overwritten.


βœ… Method 2: Permanent Change (Recommended)

πŸ“ Step 1: Create or Edit /etc/systemd/resolved.conf

sudo nano /etc/systemd/resolved.conf

Add or update the [Resolve] section like this:

[Resolve]
DNS=1.1.1.1 8.8.8.8
FallbackDNS=9.9.9.9

You can change the IPs to any DNS servers you prefer.

πŸ“ Step 2: Restart systemd-resolved

sudo systemctl restart systemd-resolved

πŸ“ Step 3: (Optional) Create a symlink for /etc/resolv.conf

If /etc/resolv.conf is not linked properly, link it to systemd-resolved:

sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Check the link:

ls -l /etc/resolv.conf

βœ… Method 3: Change DNS via NetworkManager (if installed)

If your server uses NetworkManager, you can change DNS per connection.

  1. List connections:

    nmcli connection show
  2. Set custom DNS:

    nmcli connection modify <connection-name> ipv4.dns "1.1.1.1 8.8.8.8"
    nmcli connection modify <connection-name> ipv4.ignore-auto-dns yes
  3. Restart the connection:

    nmcli connection down <connection-name> && nmcli connection up <connection-name>

πŸ“¦ Common DNS Providers

Provider DNS IPs
Cloudflare 1.1.1.1, 1.0.0.1
Google 8.8.8.8, 8.8.4.4
Quad9 9.9.9.9, 149.112.112.112

βœ… How to Verify Your Current DNS

Run the following command to check which DNS is being used:

systemd-resolve --status

Or check /etc/resolv.conf:

cat /etc/resolv.conf

🧼 Troubleshooting

  • If your DNS doesn't seem to update, make sure no other service (like dhclient or NetworkManager) is overwriting it.

  • Restart your networking or reboot the system if needed:

    sudo systemctl restart systemd-networkd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment