I've made the changes and so far no leak. I haven't made any Adaptive QoS changes (normally adjusting the upload/download bandwidth if enough) but if I do, I'll see if the script stops working.Update: reboot worked fine
I poked at the unbound.postconf and it look like the “servers-file=/xxx/xxx”gets deleted from the dnsmasq.conf so that’s where the leak is coming from.
I moved the “sh ../unbound.postconf $1” right under the “. /opt/...post-conf.div” line when I re-enabled so hopefully that fixes it. Previously uidivstats was before the unbound.postconf.
I’m keeping the extra server=127.0.0.1#53535 line in my dnsmasq.add file for now in case unbound.postconf fails but so far so good.
Appreciate the update.Automatic reboot this morning and nothing would load. I checked my dnsmasq.conf and the unbound.conf definitely ran. So that’s not the issue but it didn’t run on reboot yesterday so obviously there is something else up the chain.
My logs have not helped so far but I’m going to keep digging deeper. The sleep 30 && service restart_vpnc1 is an adequate solution for now but IMO that’s just a bandaid. It’s a pretty good bandaid but in the long run I really want to figure out the core issue.
Thanks for the lag update. I hadn’t noticed anything on my end but I was keeping an eye on it since I’ve been tweaking things. Glad you got it figured out.Appreciate the update.
As mentioned in my previous post, im back to using the original setup.
It seems I was having slow downs with the "server=127...." command. I'm currently not using the "sleep 30" command as well.
I rebooted the router a couple of times and all booted fine with script still working.
I will keep the "sleep30" command but I'm currently running without it to test.
Update: I found out where my lag was coming from. I had assigned a static IP address to my mobile phone, however, this IP address was already being used by another device. User error on my end. Thought I would comment here. I'm testing your recent changes again.
Thanks again!
I'm using the same setup as you. I'll continue to monitor and post any findings! Appreciate the info/update.Thanks for the lag update. I hadn’t noticed anything on my end but I was keeping an eye on it since I’ve been tweaking things. Glad you got it figured out.
Update on my end: The extra server line has been removed since the unbound.postconf seems to be running without issue. Additionally I’ve removed the sleep and vpn restart from the services-start script so I can test.
As of right now everything seems to be running fine but Ive been here before only to have the issue come back up a few days later. I’m really hoping the problem was the dnsmasq.postconf script.
The post-conf.div file is set to run in the current shell to set up the environment. I’m wondering if the uidivstats running before the unbound.postconf was messing up the environment somehow.
@Martineau can you provide any insight into whether or not uidivstats running in a sub shell could mess up the parent environment set up by post-conf.div?
#!/bin/sh
Check_Tun11_Con() {
ping -c1 -w1 -I tun11 9.9.9.9
}
Delete_Rules() {
iptables-save | grep "unbound_rule" | sed 's/^-A/iptables -t mangle -D/' | while read CMD;do $CMD;done
}
Add_Rules() {
iptables -t mangle -A OUTPUT -d "$wan0_dns0"/32 -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "$wan0_dns1"/32 -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "$wan0_dns0"/32 -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "$wan0_dns1"/32 -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x1000/0x1000
iptables -t mangle -A OUTPUT -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x1000/0x1000
}
Unbound_vc1() {
Add_Rules
/jffs/addons/unbound/unbound_manager.sh vpn=1 &
logger -st "($(basename "$0"))" $$ Ending Script Execution
}
Unbound_vpnDisable() {
Delete_Rules
/jffs/addons/unbound/unbound_manager.sh vpn=disable &
logger -st "($(basename "$0"))" $$ Ending Script Execution
}
Poll_Tun11() {
Delete_Rules
sleep 5
timer=5
while [ $timer -lt 300 ]; do
Check_Tun11_Con
if [ "$?" -eq 0 ]; then
Unbound_vc1
logger -st "($(basename "$0"))" $$ Ending Script Execution
exit 0
fi
sleep 1
timer++
done
logger -st "($(basename "$0"))" $$ Script Execution Timeout
exit 3
}
if [ -z "$1" ]; then
logger -st "($(basename "$0"))" $$ Script Arg Missing
exit 1
else
logger -st "($(basename "$0"))" $$ Starting Script Execution
wan0_dns0="$( (nvram get wan0_dns) | awk '{print $1}' )"
wan0_dns1="$( (nvram get wan0_dns) | awk '{print $2}' )"
if [ "$wan0_dns1" = "" ]; then
wan0_dns1 = $wan0_dns0
elif [ "$wan0_dns0" = "" ]; then
logger -st "($(basename "$0"))" $$ wan0_dns is NULL
exit 2
else
if [ "$wan0_dns0" = "" ]; then
wan0_dns0 = $wan0_dns1
fi
case "$1" in
start)
Poll_Tun11
exit 0;;
stop)
Unbound_vpnDisable
exit -1;;
*)
logger -st "($(basename "$0"))" $$ Script Arg Invalid
exit 1;;
esac
fi
fi
#!/bin/sh
Check_Tun11_Con() {
ping -c1 -w1 -I tun11 9.9.9.9
}
Delete_Rules() {
iptables-save | grep "unbound_rule" | sed 's/^-A/iptables -t mangle -D/' | while read CMD;do $CMD;done
}
Add_Rules(){
Delete_Rules
iptables -t mangle -A OUTPUT -d "${wan0_dns##*.*.*.* }"/32 -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "${wan0_dns%% *.*.*.*}"/32 -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "${wan0_dns##*.*.*.* }"/32 -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "${wan0_dns%% *.*.*.*}"/32 -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x1000/0x1000
iptables -t mangle -A OUTPUT -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x1000/0x1000
}
Call_unbound_manager() {
/jffs/addons/unbound/unbound_manager.sh vpn="$1"
}
Poll_Tun11() {
timer=$1
[ -z $timer ] && Post_log "Error Timeout" && exit 1 || sleep 2
Check_Tun11_Con && Add_Rules && Call_unbound_manager "1" || Poll_Tun11 "$((timer--))"
}
Post_log() {
$(logger -st "($(basename "$0"))" $$ "$1")
}
[ -z "$1" ] && Post_log "Script Arg Missing" && exit 1 || Post_log "Starting Script Execution"
wan0_dns="$(nvram get wan0_dns)"
Delete_Rules
case "$1" in
start)
Poll_Tun11 "150" && Post_log "Ending Script Execution" && exit 0;;
stop)
Call_unbound_manager "disable" && Post_log "Ending Script Execution" && exit 0;;
*)
Post_log "Script Arg Invalid" && exit 1;;
esac
Yep just look at the IP sets. The name of your ipset in this case is WAN_IP so the only thing in that set would be whatismyip.com. Basically the “ dnsmasq=“ starts a comma separated list of domains so you can add as many or as few as you want to that list. I just use it for stuff that blocks the vpn and to check that the script is working. If you cat the dnsmasq configuration file you should be able to see the domains and which set they are associated with. It’s also in x3mRouting’s stuff so it added it to dnsmasq configuration at startup.This might be the wrong place for this question but here it goes:
I use the following example code to route certain addresses to WAN even though the device is using VPN via policy rules in the GUI:
x3mRouting ALL 1 WAN_IP dnsmasq=whatismyip.com
I found this is useful for banking, email, etc.
All I do is ssh into my router and input this code and it works. Is there a way I can see a list of all the websites I added to route over WAN?
@Swinson, this is not related to the question above but I noticed there's an alpha VPN Director testing brewing for the upcoming 386.3 RMerlin fw. I don't think your script will be affected by 386.3 correct?Yep just look at the IP sets. The name of your ipset in this case is WAN_IP so the only thing in that set would be whatismyip.com. Basically the “ dnsmasq=“ starts a comma separated list of domains so you can add as many or as few as you want to that list. I just use it for stuff that blocks the vpn and to check that the script is working. If you cat the dnsmasq configuration file you should be able to see the domains and which set they are associated with. It’s also in x3mRouting’s stuff so it added it to dnsmasq configuration at startup.
Honestly I have no idea. I can look into it though. This is just kind of a hobby project so I can apply what I’m learning in my classes/from the wonder that is the internet. Sounds interesting though.@Swinson, this is not related to the question above but I noticed there's an alpha VPN Director testing brewing for the upcoming 386.3 RMerlin fw. I don't think your script will be affected by 386.3 correct?
Yep just look at the IP sets. The name of your ipset in this case is WAN_IP so the only thing in that set would be whatismyip.com. Basically the “ dnsmasq=“ starts a comma separated list of domains so you can add as many or as few as you want to that list. I just use it for stuff that blocks the vpn and to check that the script is working. If you cat the dnsmasq configuration file you should be able to see the domains and which set they are associated with. It’s also in x3mRouting’s stuff so it added it to dnsmasq configuration at startup.
I noticed that my DNS is leaking since upgrading to 386.3. I use Unbound and x3mRouting and Unbound says the requests are going through the VPN tunnel. I'm not sure where the problem is for that issue.
I use the DNS setting to exclusive but Unbound works. I'm using firmware 386.02_6 thoughI posted to the wrong thread last time, which doesn't help since these are such specific use cases.
I also use Swinson's scripts. If I set DNS to Exclusive, I don't leak but I also don't use Unbound and don't get local DNS resolving any longer.
sh /jffs/scripts/x3mRouting/x3mRouting.sh 1 0 WAN_IP dnsmasq=whatsmyip.com
sh /jffs/scripts/x3mRouting/x3mRouting.sh ALL 1 VPN_IP dnsmasq=whatismyip.com
/jffs/scripts/unbound_via_vc1.sh start &
/jffs/scripts/unbound_via_vc1.sh stop &
modprobe xt_comment
#!/bin/sh
Check_Tun11_Con() {
ping -c1 -w1 -I tun11 9.9.9.9
}
Delete_Rules() {
iptables-save | grep "unbound_rule" | sed 's/^-A/iptables -t mangle -D/' | while read CMD;do $CMD;done
}
Add_Rules(){
Delete_Rules
iptables -t mangle -A OUTPUT -d "${wan0_dns##*.*.*.* }"/32 -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "${wan0_dns%% *.*.*.*}"/32 -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "${wan0_dns##*.*.*.* }"/32 -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -d "${wan0_dns%% *.*.*.*}"/32 -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x8000/0x8000
iptables -t mangle -A OUTPUT -p tcp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x1000/0x1000
iptables -t mangle -A OUTPUT -p udp --dport 53 -m comment --comment unbound_rule -j MARK --set-mark 0x1000/0x1000
}
Call_unbound_manager() {
/jffs/addons/unbound/unbound_manager.sh vpn="$1"
}
Poll_Tun11() {
timer=$1
[ -z $timer ] && Post_log "Error Timeout" && exit 1 || sleep 2
Check_Tun11_Con && Add_Rules && Call_unbound_manager "1" || Poll_Tun11 "$((timer--))"
}
Post_log() {
$(logger -st "($(basename "$0"))" $$ "$1")
}
[ -z "$1" ] && Post_log "Script Arg Missing" && exit 1 || Post_log "Starting Script Execution"
wan0_dns="$(nvram get wan0_dns)"
Delete_Rules
case "$1" in
start)
Poll_Tun11 "150" && Post_log "Ending Script Execution" && exit 0;;
stop)
Call_unbound_manager "disable" && Post_log "Ending Script Execution" && exit 0;;
*)
Post_log "Script Arg Invalid" && exit 1;;
esac
sleep 30 && service restart_vpnclient1 &
/jffs/addons/unbound/unbound_rpz.sh startup # Unbound_RPZ.sh
sleep 30 && sh /jffs/scripts/unbound_via_vc1.sh start &
/jffs/scripts/unbound_via_vc1.sh start
iptables -nvL OUTPUT -t mangle
ip rule
0: from all lookup local
9995: from all fwmark 0x1000/0x1000 lookup ovpnc1
10010: from 192.168.1.124 lookup main
10210: from 192.168.1.139 lookup ovpnc1
32766: from all lookup main
32767: from all lookup default
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!