Restart interface

I want to restart wireguard network every day at 17:30. When I run this command in cmd, everything works correctly.
ifdown wg0 && sleep 10 && ifup wg0
If I set it in crontab it doesn't work
crontab -e

30 17 * * * ifdown wg0 && sleep 10 && ifup wg0

I always use full paths in crontab because I'm not sure what the env looks like, maybe that's the issue here?

/sbin/ifdown wg0 && /bin/sleep ...

Look in the log, too, should give you some hints.

logread -e cron

I'm sorry, it's my fault. When testing, I had set the wrong UTC time.
It also works with relative path.

logread -f | grep cron
Wed Jun 26 20:00:00 2024 cron.err crond[5797]: USER root pid 5823 cmd ifdown wg0 && sleep 5 && ifup wg0

For our education, what is the rationale behind a daily restart of the wg interface?


Sometimes I need to connect to the OpenWRT router remotely. Interface wg0 is wireguard VPN. However, many times I cannot connect. If I restart the wg0 interface, the connection is restored.
That's why I set the interface to restart once a day.

Then it looks like there is something wrong with your router/configuration.

1 Like

It is possible. However, restarting the interface will definitely help. :slightly_smiling_face: