How to change DNS settings on Linux
Follow this quick guide to start using DNS.SB on your Linux device.
Debian
ℹ️
The guide also works with most common Linux distributions
Edit /etc/resolv.conf
sudo vim /etc/resolv.conf
Replace the nameserver
lines with
- For IPv4
/etc/resolv.conf
nameserver 185.222.222.222
nameserver 45.11.45.11
- For IPv6
/etc/resolv.conf
nameserver 2a09::
nameserver 2a11::
You can also lock this file for security purpose
First, install e2fsprogs
:
sudo apt install e2fsprogs -y
Then, lock the /etc/resolv.conf
file:
sudo chattr +i /etc/resolv.conf
Or unlock it with sudo chattr -i /etc/resolv.conf
Ubuntu 18.04 and later
Since Ubuntu 18.04, you shoud make the change in netplan configs at /etc/netplan/*.yaml
, this file could be 50-cloud-init.yaml
or something like 01-netcfg.yaml
Open this file and it looks like
/etc/netplan/01-netcfg.yaml
network:
version: 2
ethernets:
eth0:
addresses:
- 192.0.2.2/24
gateway4: 192.0.2.1/24
match:
macaddress: 01:23:45:67:89:AB
nameservers:
addresses:
- 198.51.100.1
- 203.0.113.1
search: []
set-name: eth0
Replace the nameservers
section with
nameservers:
addresses:
- 185.222.222.222
- 45.11.45.11
Then run the following command
sudo netplan apply
You can check your current DNS assignment by running the systemd-resolve
command
systemd-resolve --status