How to Customize the hosts File in Asuswrt-Merlin
About
With dnsmasq you are able to create custom domains within your network or route existing domains to different IP addresses. It's very handy when you want to create a home page with links to your NAS storage, printer and other clever things within your household. This can also be used to block access to domains by routing them to a different IP address, so you can block advertising within some applications.
Adjust router configuration
- Go to
Administration -> System - Enable:
Enable JFFS custom scripts and configsconfig option - Enable:
Enable SSHconfig option - Go to
AiProtection -> DNS Filtering(Parental Controls -> DNSFilteron older models) - Disable:
Enable DNS-based Filtering
Adjust DHCP Server Options
- Go to
LAN -> DHCP Server DNS Server 1should contain your router's IP address.- If
Advertise routers IP in addition to user specified DNSis enabled all custom DNS addresses will be appended to the address list given to the clients when they lease an IP address. So if you want to be able to resolve names without specifying the router's address as the name server to do the resolution then make sure this setting is turned off. - Turn off
Forward local domain queries to upstream DNSto prevent your private DNS resolution requests from being passed to the Internet.
Connect to your router
Connect to your router through SSH (you can use PuTTY on Windows). The default IP address is 192.168.1.1, use the same credentials as in the web interface. (How to use putty)
Edit dnsmasq config options
-
Create configuration file for dnsmasq:
touch /jffs/configs/dnsmasq.conf.add -
Edit configuration file:
vi /jffs/configs/dnsmasq.conf.add.For typing, press
I, to quit typing pressESC, to delete line pressESCand then writeddand pressENTER. -
Add configuration for resolving domain names into
dnsmasq.conf.add-
Resolve one domain to IP, Explanation: resolves
test.comdomain to IP127.0.0.1or::1when using IPv6address=/test.com/127.0.0.1 address=/test.com/::1 -
Resolve more domains to same IP, Explanation: resolves listed domains to IP
127.0.0.1(you can write more)address=/test1.com/test2.com/127.0.0.1 -
To save and quit editor quit typing with
ESCand write:wqand hitENTER
-
Last steps
- Reboot router with
rebootcommand in ssh or through web interface. (Rebooting is not strictly necessary; restarting thednsmasqservice is sufficient:service restart_dnsmasq) - Go to
Administration -> Systemand disableEnable SSHconfig option
More
Reposted from: Custom domains with dnsmasq — m4recek · Asuswrt-Merlin Wiki contributors
Published 08/30/2018 · Krunk Zhou
Join the conversation