type
status
date
slug
summary
tags
category
icon
password
In OpenWRT, you can set different DNS servers for different devices individually using Dnsmasq. By leveraging the tag feature of Dnsmasq, you can implement DNS and gateway routing. For instance, some devices at home may need to route through a bypass, while others can go directly through the main gateway without the bypass, or require different DNS servers.
📝 Content
Dnsmasq is a lightweight DNS and DHCP server software. It is commonly used in small local area networks for network devices such as routers and switches. Dnsmasq is powerful and easy to configure, making it a great choice for small networks.
Features of Dnsmasq:
- DNS Caching: Dnsmasq has robust DNS caching capabilities, which can improve network performance and access speed.
- DHCP Server: It can also function as a DHCP server to assign IP addresses, subnet masks, and gateway addresses to devices in the local network, and provide them with DNS services.
- Static DHCP Allocation: Dnsmasq supports assigning reserved IP addresses based on device MAC addresses.
- DNS Record Management: It can manage DNS records, including A (address) records, CNAME (alias) records, PTR (reverse address records), and SRV (service) records, among others.
- TFTP Service: Provides boot files and other services to devices via TFTP.
Dnsmasq can run on platforms like Linux, Unix, and macOS and can be configured through simple configuration files. It is widely used in various routers and office gateway devices, such as OpenWRT, to provide DNS and DHCP services, making inter-device connectivity more convenient and faster.
By using the tag feature in Dnsmasq, you can achieve DNS and gateway routing. For example, some devices at home may need to route through a bypass, while others can go directly through the main gateway without using the bypass or require different DNS servers. In such cases, rather than modifying the network configuration of each device individually (especially when dealing with numerous devices like TVs or IoT devices), you can use the tag feature of Dnsmasq.
Configuration File Editing Method
The
dnsmasq.conf
file in OpenWRT is located in the /etc
directory and can be edited using vim. Once configured, it will be automatically distributed to the corresponding clients.Advanced Tag Configuration
- Edit Dnsmasq Configuration:
First, you need to define tags and corresponding DHCP options in OpenWRT's Dnsmasq configuration file, typically configured in
/etc/config/dhcp
.- Define Tags and Assign Gateways and DNS:
You can define tags and corresponding DHCP options as follows:
config tag 'custom_client'
: Defines a tagcustom_client
and specifies the gateway and DNS IP addresses viadhcp_option
.
option dhcp_option '3,192.168.1.1'
: Assigns gateway192.168.1.1
to clients with this tag.
option dhcp_option '6,8.8.8.8,8.8.4.4'
: Assigns DNS servers8.8.8.8
and8.8.4.4
to clients with this tag.
config host
: Defines a specific client configuration.
option mac '00:11:22:33:44:55'
: The client's MAC address used to identify the device.
option tag 'custom_client'
: Associates this client with thecustom_client
tag to get the respective gateway and DNS settings.
option ip '192.168.1.100'
: Optional, assigns a static IP address to this client.
- Restart Dnsmasq
After configuration, restart Dnsmasq to apply the new settings:
Direct Editing via Luci Interface
You can also configure it directly through the soft router management page:
- Navigate to
Network - Interface - LAN (Local LAN Interface) - Edit - DHCP Server - Advanced Settings
.
In the DHCP options section, fill in:
After filling in, click save to take effect.
📎 Reference
有关Notion安装或者使用上的问题,欢迎您在底部评论区留言,一起交流~