What's new

[SOLVED] Problem with wan-start script

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

decedion

Occasional Visitor
The /jffs/scripts/wan-start of my router has the next content:
Code:
#!/bin/sh

# Wait up to 15 seconds to make sure /opt partition is mounted
i=0
while [ $i -le 15 ]
do
    if [ -d /opt/tmp ]
    then
        break
    fi
    sleep 1
    i=`expr $i + 1`
done

# Now resolve DNS name for NTP server
ntp_name=$(nvram get ntp_server0)
grep "$ntp_name" /etc/hosts > /dev/null 2>&1 || \
for ip in $(/opt/sbin/dnscrypt-proxy-hostip $ntp_name)
do
    echo $ip $ntp_name >> /etc/hosts
done

# Create hosts file with URLs to block
wget -qO- "http://winhelp2002.mvps.org/hosts.txt" "http://someonewhocares.org/hosts/zero/hosts" "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&startdate[day]=&startdate[month]=&startdate[year]=&mimetype=plaintext&useip=0.0.0.0" | grep -w ^0.0.0.0 | sed $'s/\r$//' | sort -u > /jffs/hosts.adblock

# and restart NTP client to eliminate 4-5 mins delay
killall ntp && sleep 1
service restart_ntpc
service restart_dnsmasq

The problem is in next portion of code:
Code:
# Now resolve DNS name for NTP server
ntp_name=$(nvram get ntp_server0)
grep "$ntp_name" /etc/hosts > /dev/null 2>&1 || \
for ip in $(/opt/sbin/dnscrypt-proxy-hostip $ntp_name)
do
    echo $ip $ntp_name >> /etc/hosts
done

It doesn't work, this is the content of /etc/hosts:
Code:
127.0.0.1 localhost.localdomain localhost
192.168.1.1 router.asus.com
192.168.1.1 www.asusnetwork.net
192.168.1.1 www.asusrouter.com
192.168.1.1 RT-N66U.RT-N66U RT-N66U

I have executed the script in debug mode and this is the output of that portion of code:
Code:
# Now resolve DNS name for NTP server
ntp_name=$(nvram get ntp_server0)
+ nvram get ntp_server0
+ ntp_name=es.pool.ntp.org
grep "$ntp_name" /etc/hosts > /dev/null 2>&1 || \
for ip in $(/opt/sbin/dnscrypt-proxy-hostip $ntp_name)
do
    echo "$ip $ntp_name" >> /etc/hosts
done
+ grep es.pool.ntp.org /etc/hosts
+ /opt/sbin/dnscrypt-proxy-hostip es.pool.ntp.org
+ echo 81.184.154.182 es.pool.ntp.org
+ echo 157.88.196.27 es.pool.ntp.org
+ echo 147.83.123.133 es.pool.ntp.org

It should work! I don't find where is the problem... :confused:
Please, someone sees the error?
Thanks. Regards.
 
Last edited:
Solved

Solved:
Code:
# Now resolve DNS name for NTP server
rm -f /jffs/configs/hosts.add
ntp_name=$(nvram get ntp_server0)
for ip in $(/opt/sbin/dnscrypt-proxy-hostip $ntp_name)
do
    echo $ip $ntp_name >> /jffs/configs/hosts.add
done
 
This seems to be broken on the latest fw .42 and I get no internet connection due to the time not being updated and dnscrypt timestamps. I have downgraded again. Any one else notice?
 
This seems to be broken on the latest fw .42 and I get no internet connection due to the time not being updated and dnscrypt timestamps. I have downgraded again. Any one else notice?


I had this issue. I fixed it by putting "service restart_dnsmasq" after the done statement, before the NTP restart.
 
I had this issue. I fixed it by putting "service restart_dnsmasq" after the done statement, before the NTP restart.

This is incorrect. If you put "service restart_dnsmasq" before
Code:
# Create hosts file with URLs to block
wget -qO- "http://winhelp2002.mvps.org/hosts.txt" "http://someonewhocares.org/hosts/zero/hosts" "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&startdate[day]=&startdate[month]=&startdate[year]=&mimetype=plaintext&useip=0.0.0.0" | grep -w ^0.0.0.0 | sed $'s/\r$//' | sort -u > /jffs/hosts.adblock

The hosts.adblock address won't be added.

Instead you should change the order in this code block:
Code:
# and restart NTP client to eliminate 4-5 mins delay
killall ntp && sleep 1
service restart_ntpc
service restart_dnsmasq

By:
Code:
service restart_dnsmasq
# and restart NTP client to eliminate 4-5 mins delay
killall ntp && sleep 1
service restart_ntpc
 
I'm using the last firmware without problems.

Perhaps you are not using unbound... The following change was made to the latest firmware:

- CHANGED: Make the router use dnsmasq for internal name
resolution rather than directly using the WAN DNS.

As I am using dnscrypt coupled with unbound for dns querying and dnsmasq for dhcp/static dhcp hosts, not only was ntp failing, but unbound failed to start properly resulting in no internet access and ddns failing to update (quite a mess).

I had to reset the router and start with a clean install in order to troubleshoot as I was tackling numerous failures... First, unbound stopped answering client requests on interface 0.0.0.0 due to some kernel issue (had to dig around quite a bit for this). The solution was to add multiple interfaces to the configuration file - interface: 127.0.0.1, interface: 10.0.0.1 ... this would allow unbound to respond to queries on localhost (for DDNS, NTP etc.) and on 10.0.0.1 (my local IP subnet).

I then proceeded to fix dnsmasq by appending my custom config to the router's default config vs running my own config using dnsmasq.conf which was working prior to .42

The last change was to modify my wan-start script to:

Code:
#!/bin/sh

# Wait up to 15 seconds to make sure /opt partition is mounted
i=0
while [ $i -le 15 ]
do
    if [ -d /opt/tmp ]
    then
        break
    fi
    sleep 1
    i=`expr $i + 1`
done

# Now resolve DNS name for NTP server
ntp_name=$(nvram get ntp_server0)
grep "$ntp_name" /mnt/data/scripts/hosts.add > /dev/null 2>&1 || \
for ip in $(/opt/sbin/dnscrypt-proxy-hostip $ntp_name)
do
    echo $ip $ntp_name >>  /mnt/data/scripts/hosts.add
done

# Download combined ad blocking file
wget -qO- "http://winhelp2002.mvps.org/hosts.txt" "http://someonewhocares.org/hosts/zero/hosts" "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&startdate[day]=&startdate[month]=&startdate[year]=&mimetype=plaintext&useip=0.0.0.0" | grep -w ^0.0.0.0 | sed $'s/\r$//' | sort -u > /tmp/mnt/data/adblock/hosts.clean

# Restart dnsmasq
service restart_dnsmasq && sleep 1

# Restart Unbound after restarting dnsmasq as unbound is dependent on dnsmasq for local querying
/opt/etc/init.d/S61unbound restart && sleep 1

# and restart NTP client to eliminate 4-5 mins delay
killall ntp && sleep 1
service restart_ntpc

Note that I am writing the ntp hosts to /mnt/data/scripts/hosts.add instead of /etc/hosts as they were not being appended to /etc/hosts for some reason. I also didn't want to wear out the router's flash memory by writing to it on every reboot.

I also noticed that the service dhcp/zcip client was binding itself to eth0 on 169.254.151.111 which was not present in .41 .. Prior to resetting the router, I was not able to get dnscrypt to work properly as all outbound requests were being forwarded to 169.254.151.111 instead of dnscrypt.eu's ips - Strange!!

Edited: forgot to mention that I created a symlink for hosts.add in /jffs/config/ pointing to /mnt/data/scripts/hosts.add
 
Last edited by a moderator:
I had a look at the hosts.add and the 1st entry ip address did not respond to ping so I removed it and the wan came up after re running wan start. I then re-ran wan-start again and wan came up again. I have not rebooted yet.

I see hosts.add gets recreated each time wan-start is run with different ntp ip addresses, where do these different addresses come from? Is it necessary to recreate the file each time, can we just have a static file?
 
Last edited:
You should open another thread. These problems are different of my initial question and the title of this thread is "[SOLVED]...."
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top