On one of my systems, I use dnsmasq as my DNS resolver. This system is also an OpenVPN client.
When the system comes online, it gets the ISP's DNS servers from the router though a DHCP request. It places those in resolv.conf.auto
.
It then uses those DNS servers to resolve a dynamic DNS name that auto-selects the best performing VPN server, after which it connects to that VPN server.
The VPN server has its own DNS server, which it provides to the OpenVPN client. So I use the following script to alter the resolv.conf.auto file when the tunnel comes online:
#!/bin/shmv /tmp/resolv.conf.auto /tmp/resolv.conf.auto.holdecho $foreign_option_1 | sed -e 's/dhcp-option DOMAIN/domain/g' -e 's/dhcp-option DNS/nameserver/g'> /tmp/resolv.conf.autoecho $foreign_option_2 | sed -e 's/dhcp-option DOMAIN/domain/g' -e 's/dhcp-option DNS/nameserver/g'>> /tmp/resolv.conf.autoecho $foreign_option_3 | sed -e 's/dhcp-option DOMAIN/domain/g' -e 's/dhcp-option DNS/nameserver/g'>> /tmp/resolv.conf.auto
This auto-executes as soon as the tunnel comes online as part of my OpenVPN client configuration.
However, whenever I make any change to my network settings or DNSMasq, it regenerates the resolv.conf.auto
with the ISP's DNS servers, resulting in a loss of name resolution.
Is there anything I can link to the dnsmasq reload
or restart
or similar network service restarts?
If it matters, I'm running this on OpenWRT.
EDIT:Since the resolv.conf also resets on a DHCP renew, I think the best option here would be to create a shell script that checks if an interface is up and then verifies and if needed corrects the resolv.conf. Probably by using cp/mv actions, since the VPN's DNS server is dynamic (it is in the 10-range though). Which I then add as a cron-job.
I'm sure somebody here can help with that, right?