Custom DNS Entry

Hello, I'm very new in here.
I just wanted to know how can I resolve an IP address internally before it goes and ask the dns server.
Ex: someone typed youtube.com and get redirected to 127.0.0.1
I tried editing etc/hosts file but it is not working.
N.B: I'm not using GUI.

In /etc/config/dhcp

config domain
	option name 'youtube.com'
	option ip '127.0.0.1'

Or with UCI

uci add dhcp domain
uci set dhcp.@domain[-1].name="youtube.com"
uci set dhcp.@domain[-1].ip="127.0.0.1"
uci commit dhcp
/etc/init.d/dnsmasq restart

See

4 Likes

On a linux system there are two files, which determine the behaviour of the resolver:

  1. /etc/host.conf (old way)
  2. /etc/nsswitch.conf (new way)

/etc/host.conf contains the following line:

order hosts,bind

/etc/nsswitch.conf contains the following line:

hosts: files dns

You can give it a try.

1 Like

There's another method which is better suited to block domains and subdomains.

If the issue persists, make sure to disable DoH in the browser and set up DNS hijacking.

See also parental controls for alternatives.

1 Like

Can you please tell me in details? Actually I'm new to the firmware.

There are no further details, just ssh to the router and on the cmdline type the following commands:

echo "order hosts,bind" >> /etc/host.conf
echo "hosts: files dns" >> /etc/nsswitch.conf

Otherwise

man host.conf

and

man nsswitch.conf

are your friends.