Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| gentoo:wireguard [2025/02/06 10:03] – [Port Forwarding] willy | gentoo:wireguard [2026/03/19 08:21] (current) – [Watchdog] willy | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== WireGuard ====== | + | ====== |
| [[https:// | [[https:// | ||
| Line 70: | Line 70: | ||
| rc-update add wg-quick.wg0 default | rc-update add wg-quick.wg0 default | ||
| </ | </ | ||
| + | |||
| + | ===== Watchdog ===== | ||
| + | |||
| + | In my experience, when the main router reboots or the internet connection is switched, the wireguard tunnel might hang up for a very long time. I am not sure why this happen, it shouldn' | ||
| + | |||
| + | To ensure this doesn' | ||
| + | <file - tunnel-watchdog> | ||
| + | # | ||
| + | |||
| + | description=" | ||
| + | |||
| + | # The services you want to restart | ||
| + | SERVICES=" | ||
| + | PING_HOST=" | ||
| + | LOG="/ | ||
| + | FAIL_COUNT_LIMIT=5 | ||
| + | PING_TIMEOUT=1 | ||
| + | PING_COUNT=1 | ||
| + | |||
| + | restart_service() { | ||
| + | for i in ${SERVICES} | ||
| + | do | ||
| + | einfo " | ||
| + | / | ||
| + | done | ||
| + | } | ||
| + | |||
| + | depend() { | ||
| + | need net | ||
| + | } | ||
| + | |||
| + | start() { | ||
| + | ebegin " | ||
| + | echo $(date)" | ||
| + | while : ; do | ||
| + | # Perform a quick ping. -q quiet, -c N packets, -W T timeout | ||
| + | if ! ping -q -c ${PING_COUNT} -W ${PING_TIMEOUT} ${PING_HOST} >/ | ||
| + | fail_count=$((fail_count + 1)) | ||
| + | echo $(date)" | ||
| + | else | ||
| + | fail_count=0 | ||
| + | fi | ||
| + | |||
| + | # If we hit the threshold, restart | ||
| + | if [ " | ||
| + | echo $(date)" | ||
| + | restart_service | ||
| + | fail_count=0 | ||
| + | fi | ||
| + | |||
| + | # Wait a bit before the next check | ||
| + | sleep 5 | ||
| + | done & | ||
| + | PID=$! | ||
| + | echo ${PID} > / | ||
| + | eend 0 | ||
| + | } | ||
| + | |||
| + | stop() { | ||
| + | ebegin " | ||
| + | if [ -f / | ||
| + | PID=$(cat / | ||
| + | kill -9 " | ||
| + | rm / | ||
| + | else | ||
| + | eend 255 | ||
| + | fi | ||
| + | eend 0 | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Now make it executable add to the runlevel default and start it: | ||
| + | <code bash> | ||
| + | chmod +x / | ||
| + | rc-update add tunnel-whatchdog default | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | As a final note, don't forget to put log file **/ | ||
| + | |||
| ===== Remote access ===== | ===== Remote access ===== | ||