Home Network DNS
Introduction
Domain Name System (DNS) is a a system that associates domain names (strings) to internet protocol (IP) addresses.
Devices on a local network likely do not have an entry in global DNS. It can be tedious to enter an IP address to access these devices.
This post is an attempt to setup a home network to support local domain names using DNSMasq, as well as exposing a webserver externally with SSL.
I will be using a home installation of dnsmasq
on a mini server running debian that is always connected and available in my network.
In my router, I have ensured that this server is assigned a fixed IP address (192.168.1.175
).
Basic DNS Setup
Install dnsmasq on the server using sudo apt install dnsmasq
.
A simple DNS server has now been created. We can test this by running a dns lookup pointed to localhost: dig udia.ca @localhost
|
Basic Configuration
Let’s configure dnsmasq by modifying the file within /etc/dnsmasq.conf
.
The following is a basic setup with comments explaining what each line does:
|
The mini server I am running also has a local nginx web server running.
To expose this, I will modify the /etc/hosts
file to include:
|
After saving the hosts file, run sudo systemctl restart dnsmasq
to restart the service.
Now, local network requests to http://dns.home
and http://home
should resolve to 192.168.1.175
.
Exposing to WAN
To have the webserver here available to the external internet, I enabled dynamic dns on my router.
Within my DNS provider (Cloudflare), I add a new A
record to point to my currently assigned WAN.
Using awwong1/unifi-ddns, a DynDNS like API is exposed to my Ubiquiti router.
Within the router, I setup port forwarding to allow 80 and 443 to 192.168.1.175
.
Using acme.sh
Create a new Cloudflare API token at https://dash.cloudflare.com/profile/api-tokens with permissions:
- Zone.Zone Read
- Zone.DNS Edit
Modify the /etc/environment
file to contain the cloudflare API token and account ID as environment variables.
|
For SSL certificate provisioning, I use acmesh-official/acme.sh.
This diverges slightly from the official documentation, which recommends installing and using acme.sh as the root user.
|
Switch users to acmesh
and install acme.sh.
|
Because this is a system user, the installation script informs us that we don’t have a profile.
Invocations of the script will require us to specify the path to the executable: /home/acmesh/.acmesh/acme.sh
.
Create a ZeroSSL account and generate EAB credentials within app.zerossl.com/developer.
Register the EAB credentials within acme.sh:
|
Issue a certificate for home.udia.ca
.
|
Once this certificate is issued, it must be installed.
Let’s create a folder to store our certs and ensure the acmesh user can modify it.
|
|
A basic nginx configuration that supports the previous acme.sh certificate installation follows:cat /etc/nginx/sites-available/home
|