How to Set Up Local DNS Resolver with Unbound on Ubuntu 22.04
How to Set Up Local DNS Resolver with Unbound on Ubuntu 22.04
Setting up a local DNS resolver is an excellent way to improve your network’s performance and enhance privacy. Unbound is a popular DNS resolver known for its speed, security, and flexibility. In this guide, we’ll walk you through the steps to install and configure Unbound on Ubuntu 22.04.
1. Installing Unbound
First, you need to install Unbound. Open your terminal and run the following commands:
sudo apt update
sudo apt install unbound
Once the installation is complete, you can check the version of Unbound to ensure it’s installed correctly:
unbound -V
2. Basic Configuration
Unbound’s default configuration file is located at /etc/unbound/unbound.conf. Before editing it, it’s a good practice to back up the original file:
sudo cp /etc/unbound/unbound.conf /etc/unbound/unbound.conf.backup
Now, open the configuration file in your preferred text editor:
sudo nano /etc/unbound/unbound.conf
2.1 Setting Up Basic Options
In the configuration file, you’ll want to set up some basic options. Locate the section for server: and add or modify the following parameters:
server:
verbosity: 1
interface: 0.0.0.0
access-control: 127.0.0.1/32 allow
access-control: ::1 allow
access-control: 192.168.1.0/24 allow
outgoing-range: 2048
num-threads: 4
cache-max-ttl: 86400
cache-min-ttl: 3600
Explanation of Parameters:
verbosity: Sets the logging level. 0 is silent, 1 is errors only, and higher values include more detailed logs.
interface: Specifies which network interface Unbound should listen on. Setting it to 0.0.0.0 allows it to listen on all interfaces.
access-control: Controls which IP addresses can use the DNS resolver. Adjust this based on your network configuration.
outgoing-range: Sets the number of outgoing requests that Unbound can send simultaneously.
num-threads: Defines the number of threads used to handle incoming requests.
cache-max-ttl: Maximum time-to-live for cached entries.
cache-min-ttl: Minimum time-to-live for cached entries.
2.2 Forwarding DNS Queries
If you want Unbound to forward DNS queries to other DNS servers, you can add a forward-zone section:
forward-zone:
name: “.”
forward-addr: 1.1.1.1 # Cloudflare DNS
forward-addr: 8.8.8.8 # Google DNS
This configuration forwards all queries to the specified DNS servers. You can change these addresses to any DNS servers you prefer.
3. Starting and Enabling Unbound
After configuring Unbound, start the service and enable it to run at boot:
sudo systemctl start unbound
sudo systemctl enable unbound
You can check the status of Unbound to ensure it is running correctly:
sudo systemctl status unbound
4. Testing the DNS Resolver
To verify that your local DNS resolver is functioning correctly, you can use the dig command. If you don’t have dig installed, you can install it using:
sudo apt install dnsutils
Now, run a query using your local Unbound server:
dig @127.0.0.1 example.com
You should see a response with the resolved IP address for example.com. If the response is returned successfully, your DNS resolver is set up correctly.
5. Configuring Your System to Use Unbound
To make sure your system uses the local Unbound resolver, you’ll need to update your DNS settings. You can do this by modifying the resolv.conf file:
sudo nano /etc/resolv.conf
Add the following line at the top of the file:
nameserver 127.0.0.1
To make these changes persistent, consider using the resolvconf package or NetworkManager settings, depending on your setup.
6. Troubleshooting
If you encounter issues, check the Unbound log files for error messages. Logs are typically found in /var/log/syslog or /var/log/unbound.log, depending on your logging configuration. You can view the logs with:
sudo tail -f /var/log/syslog
7. Additional Resources
For more in-depth information about Unbound and its advanced configuration options, refer to the official documentation:
Unbound Official Documentation
Conclusion
Setting up a local DNS resolver with Unbound on Ubuntu 22.04 is a straightforward process that can significantly enhance your network’s performance and privacy. By following the steps outlined in this guide, you should have a fully functional Unbound DNS resolver up and running. Experiment with different configurations and explore Unbound’s advanced features to optimize your DNS resolution experience.