Raspberry Pi DNS Settings: How to Change the DNS

Ben
Ben
@benjislab

Changing the DNS (Domain Name System) settings on your Raspberry Pi can improve your internet speed, security, and reliability. DNS servers translate domain names into IP addresses, and using a fast and secure DNS server can enhance your browsing experience. This guide will walk you through the steps to change the DNS settings on your Raspberry Pi.

Equipment Needed

  • Raspberry Pi (any model)
  • MicroSD card with Raspberry Pi OS installed
  • Internet connection
  • Access to the command line (via monitor and keyboard or SSH)

Step 1: Access Your Raspberry Pi

Using a Monitor and Keyboard

  1. Connect your Raspberry Pi:

Connect your Raspberry Pi to a monitor and keyboard. Power it on and log in to the Raspberry Pi OS.

Using SSH

  1. Find the IP Address:

Find your Raspberry Pi’s IP address using your router’s client list or a network scanning tool.

  1. SSH into your Raspberry Pi:

Use an SSH client like PuTTY (Windows) or the terminal (macOS/Linux) to connect to your Raspberry Pi.

ssh pi@<your_raspberry_pi_ip>

Replace <your_raspberry_pi_ip> with the actual IP address of your Raspberry Pi.

Step 2: Change DNS Settings

You can change the DNS settings by editing the /etc/dhcpcd.conf file.

  1. Open the dhcpcd.conf file:
sudo nano /etc/dhcpcd.conf
  1. Add or Modify DNS Server Settings:

Scroll to the bottom of the file and add the following lines to specify your preferred DNS servers. For example, to use Google’s DNS servers:

interface eth0
static domain_name_servers=8.8.8.8 8.8.4.4
    
interface wlan0
static domain_name_servers=8.8.8.8 8.8.4.4
  • eth0 is for Ethernet connections.
  • wlan0 is for Wi-Fi connections.

Replace 8.8.8.8 and 8.8.4.4 with the IP addresses of your preferred DNS servers. Some popular DNS servers include:

  • Google DNS: 8.8.8.8, 8.8.4.4
  • Cloudflare DNS: 1.1.1.1, 1.0.0.1
  • OpenDNS: 208.67.222.222, 208.67.220.220
  1. Save and Exit:

Save the changes and exit the text editor. In Nano, you can do this by pressing Ctrl+X, then Y to confirm, and Enterto save.

Step 3: Restart Networking Service

To apply the new DNS settings, restart the networking service on your Raspberry Pi.

sudo systemctl restart dhcpcd

Alternatively, you can reboot your Raspberry Pi to apply the changes.

sudo reboot

Step 4: Verify DNS Settings

After restarting, verify that the new DNS settings are applied correctly.

  1. Check the Current DNS Servers:

Use the resolvectl or systemd-resolve command to check the current DNS servers being used.

resolvectl status

or

systemd-resolve --status
  1. Verify DNS Resolution:

Test the DNS resolution by pinging a domain name.

ping google.com

If the ping command returns an IP address, the DNS resolution is working correctly.

Conclusion

By changing the DNS settings on your Raspberry Pi, you can improve your internet browsing speed, security, and reliability. Whether you use Google DNS, Cloudflare DNS, OpenDNS, or any other DNS service, the steps outlined in this guide will help you configure your Raspberry Pi to use the DNS servers of your choice. Enjoy a better internet experience with optimized DNS settings on your Raspberry Pi.