[Interface]PrivateKey = REDACTEDListenPort = 55107Address = 10.99.99.2/32# port forwarding wireguard portsPostUp = iptables -t nat -A PREROUTING -p udp -i eth0 -m multiport --dport 55551,55552,55553,55554,55555,55556 -j DNAT --to-destination 10.99.99.1PostDown = iptables -t nat -D PREROUTING -p udp -i eth0 -m multiport --dport 55551,55552,55553,55554,55555,55556 -j DNAT --to-destination 10.99.99.1# packet masqueradingPreUp = iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADEPostDown = iptables -t nat -D POSTROUTING -o wg0 -j MASQUERADE[Peer]PublicKey = REDACTEDAllowedIPs = 10.99.99.1/32Endpoint = $DYNDNS_OF_MY_OPNSENSE:55599
root@opnsense01:~ # wg show wg2interface: wg2 public key: REDACTED private key: (hidden) listening port: 55599peer: REDACTED endpoint: 192.168.1.1:55107 allowed ips: 10.99.99.2/32 latest handshake: 1 minute, 22 seconds ago transfer: 5.61 MiB received, 8.44 MiB sent
/usr/local/sbin/pluginctl -s wireguard restart
interface: wg2 public key: REDACTED private key: (hidden) listening port: 55599peer: REDACTED endpoint: $CORRECT_IP:55107 allowed ips: 10.99.99.2/32 latest handshake: 16 seconds ago transfer: 5.86 MiB received, 10.24 MiB sent
root@opnsense01:~ # crontab -l | tail -n2*/1 * * * * (/usr/local/bin/keepalive_wg_tunnel.sh) > /dev/null*/5 * * * * (ping -c 5 10.99.99.2) > /dev/nullroot@opnsense01:~ # cat /usr/local/bin/keepalive_wg_tunnel.sh#!/bin/bashOPNSENSE_IP=$(/usr/local/bin/dig @1.1.1.1 +short wg01.some.domain)WG_ENDPOINT_IP=$(/usr/bin/wg show wg2|/usr/bin/grep endpoint|/usr/bin/cut -d ":" -f2|xargs)LOGFILE="/var/log/keepalive_wg.log"TIMESTAMP=`/bin/date "+%Y-%m-%d %H:%M:%S"`if [ "$OPNSENSE_IP" == "$WG_ENDPOINT_IP" ] ; then echo "DEBUG: IPs are equal, nothing to do..."else echo "DEBUG: IPs are not equal, reloading wireguard config" echo "$TIMESTAMP | BEGIN Failover restart | OPNsense: $OPNSENSE_IP | WG_endpoint: $WG_ENDPOINT_IP" >> $LOGFILE /usr/local/sbin/pluginctl -s wireguard restart /sbin/ping -c 5 10.99.99.2 echo "$TIMESTAMP | END Failover restart | OPNsense: $OPNSENSE_IP | WG_endpoint: $WG_ENDPOINT_IP" >> $LOGFILEfi