Adding "Custom DNS Server" to /tmp/resolv.conf.auto via /lib/netifd/dhcp.script

Hi All,

I would like to add a custom DNS Server IP which will resolve custom FQDN addresses.

So, ISP provided DNS server will resolve common FQDN addresses and My custom DNS server will resolve specific/custom locally provided FQDN addresses.

For this, I have added this line echo "nameserver 1.2.3.4" >> /tmp/resolv.conf.auto at end to function setup_interface() in script /lib/netifd/dhcp.script. I have outputted '/tmp/resolv.conf.auto' in dhcp.script and verified "nameserver 1.2.3.4" is successfully present in /tmp/resolv.conf.auto.

But If I view /tmp/resolv.confi.auto file from console, My DNS server is not present. Anyone can help me findout what is happening here??

Steps To Simulate :-
Empty '/tmp/dns_log.txt' file. NetIfd script output will be stored in '/tmp/dns_log.txt'.
root@OpenWrt:~# echo "" > /tmp/dns_log.txt

Empty '/tmp/resolv.conf.auto' file.
root@OpenWrt:~# echo "" > /tmp/resolv.conf.auto

To obtain new DNS address.
root@OpenWrt:~# /etc/init.d/network restart

View NetIfd script output.

root@OpenWrt:~# cat /tmp/dns_log.txt
DNS_DEBUG:NetIfd: Append Custom DNS Server: 1.2.3.4 to /tmp/resolv.conf.auto [Status: 0]
DNS_DEBUG:NetIfd: Contents of /tmp/resolv.conf.auto
# Interface wan
nameserver 8.8.8.8
search example.org
nameserver 1.2.3.4

Checking '/tmp/resolv.conf.auto' file. My DNS Server "nameserver 1.2.3.4" is lost.

root@OpenWrt:~# cat /tmp/resolv.conf.auto
# Interface wan
nameserver 8.8.8.8
search example.org
root@OpenWrt:~#

Thanks,
PerumalPreformatted text

Why don't you do one of the following:

A:
Client <> OpenWrt <> Local DNS <> Public DNS Servers Forwarders configured in Local DNS

OR

B:
Client <> Hostnames configured in OpenWrt <> Public DNS Forwarders configured in OpenWrt

Why do you not use the uci config /etc/config/dhcp and set there

list rebind_domain 'example.local'
list server '/example.local/192.168.234.10'

in dnsmasq section.

This would resolve all domains as *.example.local and example.local with the dns server 192.168.234.10.
The rebind_domain option is needed because dnsmasq prevents to resolve a domain with a local ip apart from your configured local domain.

2 Likes

Thanks for your time, I will take a look on this.

The proper solution is to simply add option dns 1.2.3.4 to any of your interfaces in /etc/config/network.
Neither do you need to edit the DHCP handler script, nor /etc/config/dhcp.

For this requirement i prefer my solution.