This guide will show you how to edit, add, or remove the DNS settings on your Linux device.
Firstly, open the terminal with the CTRL + ALT + T combination and type in the following commands:
sudo rm -r /etc/resolv.conf
sudo nano /etc/resolv.conf
You will be asked for your root password after each command line, just type it in and press Enter. When the text editor opens, you will have to type in these lines:
- Now close and save the file by clicking Ctrl + X and pressing Y.
After that, please type in one last command in the terminal and press Enter:
chattr +i /etc/resolv.conf
In case the chattr +i command does not work, try using the following command instead:
sudo chattr -f +i /etc/resolv.conf
- Lastly, restart your Linux device.
If you are a device like Raspberry PI or the steps above do not help, try the steps below:
- Open the terminal with the CTRL + ALT + T combination and type in the following commands:
sudo nano /etc/dhcpcd.conf
- You will be asked for your root password. Type it in and press Enter.
Now find the section related to your VPN network interface (Typically, it’s going to be named tun0 or tap0 for OpenVPN connections or wg0 for Wireguard connections). It might look something like this:
If this section does not exist, you can create it.
- Add or modify the static domain_name_servers line to specify the DNS servers you want to use. For example, to Surfshark’s public DNS servers, modify it like so:
static domain_name_servers=22.214.171.124 126.96.36.199
- Now save the changes by pressing CTRL + O, then press Enter. To exit, press CTRL + X.
Changes to /etc/dhcpcd.conf are generally more persistent and less likely to be overridden by automatic processes, so you do not need to apply the chattr +i command on it.
- After making changes, restart the network service to apply the new DNS settings using this command:
sudo service dhcpcd restart
Alternatively, you can reboot your Linux system.
You may also be interested in: