Come modificare in modo permanente il DNS su Debian / How to Permanently Change DNS on Debian
*ITALIANO*
Esistono diversi metodi per impostare il DNS, a seconda della configurazione. Questa guida illustra il metodo più comune che utilizza systemd-resolved o la configurazione diretta in /etc/network/interfaces o /etc/netplan.
***Metodo 1: utilizzo di systemd-resolved (sistemi Debian)***
Passaggio 1: verificare se systemd-resolved è attivo
bash
*systemctl status systemd-resolved*
Se è attivo e in esecuzione, procedere. In caso contrario, prendere in considerazione l'utilizzo del metodo 2.
Passaggio 2: creare o modificare il file di configurazione
Modificare il file di configurazione resolved:
bash
*sudo nano /etc/systemd/resolved.conf*
Aggiungere o modificare la sezione DNS:
*\[Resolve]*
*DNS=1.1.1.1 1.0.0.1*
*FallbackDNS=9.9.9.9*
Puoi sostituire gli IP con i tuoi server DNS preferiti (Cloudflare, Google, Quad9).
Passaggio 3: riavvia systemd-resolved
bash
*sudo systemctl restart systemd-resolved*
Passaggio 4: collega /etc/resolv.conf (facoltativo ma consigliato)
bash
*sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf*
Questo assicura che /etc/resolv.conf punti alla posizione corretta gestita da systemd.
***Metodo 2: per IP statico (senza systemd-resolved)***
Se si sta impostando manualmente un IP statico utilizzando /etc/network/interfaces:
Passaggio 1: modificare il file delle interfacce
bash
*sudo nano /etc/network/interfaces*
Esempio di configurazione:
bash
*auto eth0*
*iface eth0 inet static*
*address 192.168.1.100*
*netmask 255.255.255.0*
*gateway 192.168.1.1*
*dns-nameservers 1.1.1.1 1.0.0.1*
Salvare e uscire.
Passaggio 2: riavviare la rete
bash
*sudo systemctl restart networking*
***Metodo 3: se si utilizza Netplan***
Passaggio 1: modificare la configurazione di Netplan
bash
*sudo nano /etc/netplan/01-netcfg.yaml*
Esempio:
*network:*
*version: 2*
*ethernets:*
*eth0:*
*dhcp4: no*
*addresses:*
*- 192.168.1.100/24*
*gateway4: 192.168.1.1*
*nameservers:*
*addresses: \[1.1.1.1, 1.0.0.1]*
Passaggio 2: applicare la configurazione
bash
*sudo netplan apply*
Verificare che il DNS sia impostato
bash
*systemd-resolve --status*
oppure
*cat /etc/resolv.conf*
oppure
*dig *[*google.com*](http://google.com)
---
*ENGLISH*
There are a few methods to set DNS, depending on your setup. This guide covers the most common method using systemd-resolved or direct configuration in /etc/network/interfaces or /etc/netplan.
**Method 1: Using systemd-resolved (Debian Systems)**
Step 1: Check if systemd-resolved is active\
bash\
*systemctl status systemd-resolved*
If it's active and running, proceed. If not, consider using Method 2.
Step 2: Create or edit the config file\
Edit the resolved configuration file:\
bash\
*sudo nano /etc/systemd/resolved.conf*
Add or modify the DNS section:\
*\[Resolve]\
DNS=1.1.1.1 1.0.0.1\
FallbackDNS=9.9.9.9*
You can replace the IPs with your preferred DNS servers (Cloudflare, Google, Quad9).
Step 3: Restart systemd-resolved\
bash\
*sudo systemctl restart systemd-resolved*
Step 4: Link /etc/resolv.conf (optional but recommended)\
bash\
*sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf*
This ensures /etc/resolv.conf points to the right place managed by systemd.
**Method 2: For Static IP (No systemd-resolved)**
If you are manually setting a static IP using /etc/network/interfaces:\
Step 1: Edit the interfaces file\
bash\
*sudo nano /etc/network/interfaces*
Example configuration:\
bash\
*auto eth0\
iface eth0 inet static\
address 192.168.1.100\
netmask 255.255.255.0\
gateway 192.168.1.1\
dns-nameservers 1.1.1.1 1.0.0.1*
Save and exit.\
Step 2: Restart networking\
bash\
*sudo systemctl restart networking*
***Method 3: If Using Netplan***
Step 1: Edit Netplan config\
bash\
*sudo nano /etc/netplan/01-netcfg.yaml*
Example:\
network:\
version: 2\
ethernets:\
eth0:\
dhcp4: no\
addresses:\
\- 192.168.1.100/24\
gateway4: 192.168.1.1\
nameservers:\
addresses: \[1.1.1.1, 1.0.0.1]
Step 2: Apply the configuration\
bash\
*sudo netplan apply*
Verify DNS Is Set\
bash\
*systemd-resolve --status*\
or\
*cat /etc/resolv.conf*\
or\
*dig *[*google.com*](http://google.com)