Configuring Local Domain Name Resolution for Devices Connected via Wi-Fi on OpenWRT
If you’re operating an OpenWRT-based network and want all devices connected through Wi-Fi to seamlessly access a local server via a custom domain name, you’re looking to implement local DNS resolution. This setup allows users to type a familiar URL, such as https://my.home
, and have their browsers automatically redirect to your local server’s IP address (e.g., 192.168.1.100
).
Understanding the Process
At its core, what you’re aiming to achieve is known as “local DNS resolution” or “hostname mapping.” This setup makes your network more user-friendly by replacing numerical IP addresses with memorable domain names without the need for external DNS services.
Key Components and Terminology
- Hosts File: A static file used to define hostname-to-IP address mappings manually.
- DNS Server: Resolves domain names to IP addresses. On OpenWRT, this can be configured through dnsmasq or other DNS services.
- dnsmasq: A lightweight DHCP and DNS server commonly used on OpenWRT, which can be configured to provide local hostname mappings.
Implementation Guide
- Identify the Configuration File
The most common way to provide custom hostname mappings on OpenWRT is via the dnsmasq configuration. You can add custom mappings either directly in the /etc/hosts
file or by configuring dnsmasq.
-
Using
/etc/hosts
:Edit the
/etc/hosts
file to include your custom hostname:192.168.1.100 my.home
After editing, save the file.
-
Using dnsmasq Configuration:
Create or edit the custom configuration file, typically located at
/etc/dnsmasq.conf
or/etc/config/dhcp
. For persistent, automated configuration, the latter is recommended. -
Configure dnsmasq in OpenWRT
On OpenWRT, the preferred method is editing /etc/config/dhcp
. Add a host entry as follows:
sh
config host
option name 'my.home'
option ip '192.168.1.100'
After updating the configuration, restart the dnsmasq service to apply changes.
- Restart the Necessary Services
To ensure the new hostname mappings take effect, restart dnsmasq:
Share this content: