<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi, Guus<div class=""><br class=""></div><div class="">Thanks a lot for your suggestion, actually I did something else as below.</div><div class=""><br class=""></div><div class="">But one question here is if I don’t add "/sbin/ifconfig myvpn 10.0.0.1 netmask 255.255.255.0”, it seems the crontab wouldn’t trigger tinc-up, and then the ip addr of myvpn wouldn’t be configured, then it will prompt the error of "<span style="color: rgba(0, 0, 0, 0.85098); font-family: 'Helvetica Neue';" class="">Can't write to Linux tun/tap device (tun mode) /dev/net/tun: Input/output error</span><font color="rgba(0, 0, 0, 0.85098)" face="Helvetica Neue" class="">”</font></div><div class=""><br class=""></div><div class="">So I have to manually add that ifconfig command, so how can I avoid to do that, and let the tincd to invoke the tinc-up script?</div><div class=""><br class=""></div><div class=""><i class="">crontab -e (under root):</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">0 * * * * /root/add.sh >> /tmp/out.log 2>&1<br class="">30 * * * * /root/remove.sh >> /tmp/out.log 2>&1</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">/root/add.sh:</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">#!/bin/sh<br class="">echo Subnet = 54.169.128.0/17 >> /etc/tinc/myvpn/hosts/aws_sgp<br class="">echo Subnet = 54.169.0.0/17 >> /etc/tinc/myvpn/hosts/aws_sgp<br class="">/usr/sbin/tincd -n myvpn -k<br class="">sleep 1s<br class="">/usr/sbin/tincd -n myvpn --debug=3<br class="">/sbin/ifconfig myvpn 10.0.0.1 netmask 255.255.255.0</i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class=""><br class=""></i></div><div class=""><i class="">/root/remove.sh:</i></div><div class=""><br class=""></div><div class=""><i class="">#!/bin/sh<br class="">sed -i '/54.169.128.0\/17/d' /etc/tinc/myvpn/hosts/aws_sgp<br class="">sed -i '/54.169.0.0\/17/d' /etc/tinc/myvpn/hosts/aws_sgp<br class="">/usr/sbin/tincd -n myvpn -k<br class="">sleep 1s<br class="">/usr/sbin/tincd -n myvpn --debug=3<br class="">/sbin/ifconfig myvpn 10.0.0.1 netmask 255.255.255.0</i></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 26 May 2017, at 6:03 PM, Guus Sliepen <<a href="mailto:guus@tinc-vpn.org" class="">guus@tinc-vpn.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Fri, May 26, 2017 at 09:30:44AM +0800, Bright Zhao wrote:<br class=""><br class=""><blockquote type="cite" class="">Due to some routing rotation purpose, I use crontab to add below info:<br class=""><br class="">0 * * * * echo Subnet = 54.169.128.0/17 >> /etc/tinc/myvpn/hosts/aws_sgp<br class="">0 * * * * echo Subnet = 54.169.0.0/17 >> /etc/tinc/myvpn/hosts/aws_sgp<br class="">1 * * * * /usr/sbin/tincd -n myvpn -k<br class="">1 * * * * /usr/sbin/tincd -n myvpn --debug=3<br class=""><br class="">30 * * * * sed -i '/54.169.128.0\/17/d' /etc/tinc/myvpn/hosts/aws_sgp<br class="">30 * * * * sed -i '/54.169.0.0\/17/d' /etc/tinc/myvpn/hosts/aws_sgp<br class="">31 * * * * /usr/sbin/tincd -n myvpn -k<br class="">31 * * * * /usr/sbin/tincd -n myvpn --debug=3<br class=""></blockquote><br class="">This is not the right way to do it. Cronjobs are being run in parallel.<br class="">So if you both stop and start tinc at the same time, there is no<br class="">guarantee that it will happen in the right order. The easiest way is to<br class="">create two scripts, one that adds the Subnets and the other that removes<br class="">them, and the other that adds them.<br class=""><br class="">Another issue is that with tinc 1.0, the -k option sends a TERM signal<br class="">to the running tinc daemon, but it might take a little time before it<br class="">actually stops. So add a sleep command inbetween, or check for<br class="">/var/run/tinc.myvpn.pid to disappear.<br class=""><br class="">-- <br class="">Met vriendelijke groet / with kind regards,<br class="">     Guus Sliepen <<a href="mailto:guus@tinc-vpn.org" class="">guus@tinc-vpn.org</a>><br class="">_______________________________________________<br class="">tinc mailing list<br class=""><a href="mailto:tinc@tinc-vpn.org" class="">tinc@tinc-vpn.org</a><br class="">https://www.tinc-vpn.org/cgi-bin/mailman/listinfo/tinc<br class=""></div></div></blockquote></div><br class=""></div></body></html>