Without VPN service I would like to use custom DNS servers.
For that I have to go to Network> Interfaces> WAN> Advanced Settings, uncheck "Use DNS servers advertised by peer" and enter custom DNS servers. Right?
But almost every vpn service uses own DNS servers. How do I use these DNS servers after a vpn connection?
uci set dhcp.dnsmasq[0].resolvfile="/tmp/resolv.conf.vpn"
It must be:
uci set dhcp.@dnsmasq[0].resolvfile="/tmp/resolv.conf.vpn"
I hope this configuration is ok now:
/etc/openvpn/up.sh:
#!/bin/sh
env | sed -n -e "
/^foreign_option_.*=dhcp-option.*DNS/s//nameserver/p
/^foreign_option_.*=dhcp-option.*DOMAIN/s//domain/p
" | sort -u > /tmp/resolv.conf.vpn
uci set dhcp.@dnsmasq[0].resolvfile="/tmp/resolv.conf.vpn"
/etc/init.d/dnsmasq restart
chmod "u=rwx,g=rx,o=rx" /etc/openvpn/up.sh
/etc/openvpn/down.sh:
#!/bin/sh
uci set dhcp.@dnsmasq[0].resolvfile="/tmp/resolv.conf.auto"
/etc/init.d/dnsmasq restart
chmod "u=rwx,g=rx,o=rx" /etc/openvpn/down.sh
uci set openvpn.@openvpn[-1].script_security="2"
uci set openvpn.@openvpn[-1].up="/etc/openvpn/up.sh"
uci set openvpn.@openvpn[-1].down="/etc/openvpn/down.sh"
uci commit openvpn
service openvpn restart