Using Pi-hole to route your services internally
If you have followed our previous guides, chances are that you have a domain, some DNS records pointing to your public IP, port forwarding enabled and a Docker server running some services.
Most likely your domain resolves to your public IP from you internal network as well. This causes a problem: All the traffic between your devices (e.g. your phone) to your server (physically in the same location) gets routed trough the internet, which means you have to utilize your upload and download bandwidth at the same time (e.g. while streaming from Plex), which not only causes a slower connection but also adds an unnecessary high latency.
If you have a Pi-hole running at home (which you should) you can configure it to resolve your domain (*.example.com and example.com) to your servers local IP instead of your public IP. This means all your devices will directly connect to your server without looping through the internet, making everything faster. Yay!
Since Pi-hole is nothing else but a DNS server with some special software, we can easily configure the underlying dnsmasq service.
Here’s how we can achieve that:
Connect to your Raspberry Pi (or wherever Pi-hole is running) via SSH
Open the file
sudo nano /etc/dnsmasq.d/05-custom.conf
Add the following line (change example.com to your domain and 192.168.1.10 to your servers local IP)
Restart the DNS service
sudo pihole restartdns
You can verify the changes by looking up your domain:
[user@server ~]$ dig +short example.com 184.108.40.206
[user@server ~]$ dig +short example.com 192.168.1.10
If you don’t have
dig installed, you can use the following command to install it on Ubuntu:
sudo apt install dnsutils