[Solved] Dnsmasq specifies the network card using the specified DNS

Hi,

I had the following requirements, but I ran into some problems with the implementation

  1. The client under the router uses 114.114.114.114 to resolve the domain name, but when accessing Google, it needs to use 8.8.8.8
  2. In router local, I want it to be resolved with 114.114.114.114, including access to Googe

I added server=/google.com/8.8.8.8 to /etc/dnsmasq.conf.
For now, the first requirement is fine, but when I access Google on my router, it also uses 8.8.8.8 to resolve the domain name.
I tried to add option dns '114.114.114.114' under the WAN interface of /etc/config/network. At this time, I used nslookup www.google.com to test, and it correctly used 114.114.114.114 to resolve. However, when I used wget www.google.com and other commands, I found that it still used 8.8.8.8 to resolve

Under openwrt, is there a way to specify the network card to use the specified DNS, which should be able to meet my needs

The router itself will use the /etc/resolv.conf in order to resolve names to addresses.
By default this is a symbolic link to /tmp/resolv.conf

root@xeli:/etc# ls -la resolv.conf 
lrwxrwxrwx    1 root     root            16 Jan 30 13:21 resolv.conf -> /tmp/resolv.conf

/tmp/resolv.conf is created based on the information it gets from /etc/config/network lines option dns and option peerdns
If you don't like this, you can erase the symbolic link and create the file again adding the nameserver that you want to use for the router. In your case the line nameserver 114.114.114.114 will do the trick.

The problem is solved. Thank you for your help

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.