New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os-wireguard: add script to enable cron renewal of DNS for stale connections #2956
Conversation
Update version number
Add new version
Script for DNS renewal of all Wireguard interfaces in case of stale connections
Add "renew" action for cron
Hi, Did you successfully tested it on your machine? |
Sort of: I ran the script with "set -x" and it read the configs fine and I can use it from cron after "service configd restart" and a restart of the web ui. I cannot force a connection to go stale, though, so I cannot check if it is effective. The script basis is from the original Wireguard author (it was called reresolve.sh in the contrib directory of the wireguard tools), so it should do what is expected. It uses wg to check the timestamp of the last handshake and if it is older than ~2 minutes, it just restarts the connection. I could see everything but the restart on my script run. The only thing I added was a loop over all wireguard interface files, which are under /usr/locat/etc/wireguard on OpnSense. Also, bash is in another location, so the shebang had to be altered, |
As an initial observations, afaik bash is not included in OPNsense by default. Is it installed with the WG plugin? |
There is a dependency from os-wireguard to wireguard-tools, which in turn requires bash. wg-quick makes use of bash as well. You can check via 'pkg info -r bash' and 'pkg info -r wireguard-tools'. All of these packages are in the opnsense repo. So yes, it is installed with os-wireguard. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK for me, thx :)
net/wireguard/src/opnsense/service/conf/actions.d/actions_wireguard.conf
Outdated
Show resolved
Hide resolved
#!/usr/local/bin/bash | ||
# SPDX-License-Identifier: GPL-2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be any more Linux-y :D
.sh might break validation of shell scripting but I'll deal with this post-merge. Thanks! |
Sorry for barging in, but I want to use this now. Will this be in the next OPNSense release? Can I just put these files in my OPNSense system with the same name ( |
I suspect |
There's an issue with the script since it doesn't have executable permission, but otherwise it should work as a single patch |
( And to get the cron command to show up this is needed:
) |
Wow I didn't know there's such thing in opnsense. This is gold, thank you!
I also just found out that you renamed the files |
I managed to do this using: |
yes, I think opnsense-patch can fixup the permission given the patch :) |
Looks like something is wrong here.
Now I'm running into this issue and every configctl command failed T.T:
|
configd not coming back up? try restarting again. as for bash script error... sorry I have to pass. Sort of the reason why we don't want to offer native bash support in core. |
@meyergru can you fix the line breaks please? It seems there were some c+p issues |
Can I try to fix this? |
I have tried this and it's working
|
No it didn't until I deleted the action, |
Sorry, I edited the files in Github web UI, where you cannot set execute bits and have no control over newlines. |
Please also change |
I am currently on vacation and cannot do anything useful. |
@budimanjojo why not create your own PR with the tidy-ups you're after? :) |
Done, Please take a look |
Looks OK to me |
I am currently using a monit service to restart a stale wg interface. Working well. Just a quick question about the script. Is it meant to be run like every 5 minutes? |
Hi all, I have WG 1.11 installed with a few enpoints set up and this DNS feature would be really useful for me. But how do I enable it? I cannot see a setting under WG. Thanks in advance [edit] Ignore, I can see it under settings/cron |
You have to enable it as a cron job. |
Wireguard does DNS resolution of endpoints only on startup. Even when a keepalive is in place, a stale connection does not lead to a renewal of DNS entries in case the other side's IP has changed.
This adds a script that can be called from cron every now and then and then triggers a DNS renewal for all stale connections.