Setup home DNS service

Setup Home DNS Service

This tutorial will guide you through setting up a home DNS service using a Raspberry Pi and the BIND9 software. This setup is ideal for developers and homelab enthusiasts who need a custom domain resolution system.

Hardware or Software Requirements

Step-by-Step Instructions

    • Prepare the Raspberry Pi:

    Download the latest Raspbian image from the official Raspberry Pi website. Write this image to your microSD card using a tool like Etcher.

    • Set up the Raspberry Pi:
      • Insert the microSD card into the Raspberry Pi and connect it to your TV or monitor via HDMI, keyboard, and mouse.
      • Connect the Raspberry Pi to your local network using an Ethernet cable if possible. Alternatively, you can use Wi-Fi by configuring it in the settings.
      • Power on the Raspberry Pi and follow the initial setup wizard to configure the hostname, timezone, and other basic settings.
    • Update the System:

    Open a terminal window on your Raspberry Pi and run the following commands:

    sudo apt-get update
    sudo apt-get upgrade
    • Install BIND9:

    BIND9 is already included in Raspbian, so you can proceed to configure it. Run the following command to start the configuration process:

    sudo nano /etc/bind/named.conf.local
    • Create a Zone File:
      • Add your domain and subdomains in the zone file. For example, for a domain named "example.com", add the following lines to the end of the file:

      zone "example.com" {

        type master;

        file "/etc/bind/db.example.com";

      };

    • Create a Zone File for Your Domain:

    Create the zone file referenced in the previous step. For example, create a file named "db.example.com" with the following content:

    example.com. IN SOA ns1.example.com. admin.example.com. (
      2023100101 ; serial
      86400 ; refresh (1 day)
      7200 ; retry (2 hours)
      3600000 ; expire (100 days)
      86400 ) ; minimum (1 day)
    
    example.com. IN NS ns1.example.com.
    ns1.example.com. IN A 192.168.1.100
    www.example.com. IN A 192.168.1.100
    • Restart BIND9 Service:

    To apply the changes, restart the BIND9 service with the following command:

    sudo systemctl restart bind9
    • Test Your DNS Setup:
      • Use a tool like `dig` to test your domain resolution. For example, run:

      dig www.example.com

      This should return the IP address you configured for "www.example.com" in the zone file.

Troubleshooting Section

Conclusion

You have successfully set up a home DNS service using BIND9 on your Raspberry Pi. This setup allows you to manage custom domain resolutions for your local network or homelab environment. Enjoy the flexibility and control over your own DNS records!

Comments